Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:找不到接受参数的位置参数_Python_Powershell - Fatal编程技术网

Python:找不到接受参数的位置参数

Python:找不到接受参数的位置参数,python,powershell,Python,Powershell,我正在使用子进程将(cd)目录更改为指定的目录,但是 Set-Location : A positional parameter cannot be found that accepts argument '\Themes'. At line:1 char:1 + cd $(spicetify -c | Split-Path)\Themes 我在Windows计算机上使用它将目录更改为该特定文件夹(由Spicetify CLI创建)。它适用于Powerhsell,但不适用于我的Python脚本

我正在使用子进程将(cd)目录更改为指定的目录,但是

Set-Location : A positional parameter cannot be found that accepts argument '\Themes'.
At line:1 char:1
+ cd $(spicetify -c | Split-Path)\Themes
我在Windows计算机上使用它将目录更改为该特定文件夹(由Spicetify CLI创建)。它适用于Powerhsell,但不适用于我的Python脚本:

import subprocess

def main():
    call(["powershell", "cd", "$(spicetify -c | Split-Path)\Themes"])
def call(commands):
    subprocess.call(commands, shell=True)

if __name__=="__main__":
    main()

我认为这是一个引用问题。您需要一对周围的双引号才能传递到PowerShell。可能使用外部单引号会起作用:可能类似于
call([“powershell”、“cd”、“$(spicetify-c | Split Path)\Themes”])
的东西会起作用。我尝试过了,现在出现了这个错误:“``PS D:\Documents\code>python theme.py'Split Path)\Themes\\”不能识别为内部或外部命令、可操作程序或批处理文件```我想您可以在子表达式操作符中包含整个参数:
call([“powershell”,“cd”,“$((spicetify-c | Split Path)+'\Themes')))
在使用CMD shell进行了一些进一步的测试之后,我不得不逃避一些事情。当然,我不知道你的壳是什么。我们确实需要转义内部引号和特殊的
|
(在CMD中是特殊的)。我还必须避开路径反斜杠,但我将省略这些,因为您似乎不必:
调用([“powershell”、“cd”、“\”$(spicetify-c^分割路径)\Themes\”“])
。或者
调用([“powershell”、“cd”、“$(spicetify-c^分割路径)\Themes”])
。您的解决方案可能与此不完全相同,但我认为需要使用类似的方法。我尝试了您所说的方法,但没有给出任何错误,也没有更改目录并保持在同一目录中。我正在使用Windows 10的powershell。