如何在子进程命令行中传递字符串路径?

2024-10-01 02:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个使用subprocess.popen方法的代码,我想在设置上传递一个字符串路径,但是我不知道怎么做

这是我的密码:

screenCommand = rep_reference+"\osgedit\osgviewer.exe "

iterationsPath = str(path + "\sreplace.osg")
        command = "{0} --screen 0 --window 0 0 1920 1080 path+\sreplace.osg {1} " .format(screenCommand, listFix[e])

        process = subprocess.Popen(command)

        time.sleep(3.0)

        process.kill()

如何在我的命令设置中设置iterationsPath变量的路径


Tags: path方法字符串代码路径密码processcommand
1条回答
网友
1楼 · 发布于 2024-10-01 02:18:39

您可以将列表中的各种参数和选项与命令一起传递

例如,要在当前目录中打开VSCode,请在shell中执行以下操作:

$ code .

使用subprocess.Popen()(或subprocess.call()):

>>> import subprocess
>>> subprocess.Popen(['code', '.'])
>>>

实际上,您可以将shell命令按空格拆分

从文件中

On POSIX, if args is a string, the string is interpreted as the name or path of the program to execute. However, this can only be done if not passing arguments to the program.

https://docs.python.org/3/library/subprocess.html#subprocess.Popen

相关问题 更多 >