Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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/linux/26.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
使用Linux子系统在Python(os.subprocess)中调用外部bash命令_Python_Linux_Windows_Ubuntu_Windows Subsystem For Linux - Fatal编程技术网

使用Linux子系统在Python(os.subprocess)中调用外部bash命令

使用Linux子系统在Python(os.subprocess)中调用外部bash命令,python,linux,windows,ubuntu,windows-subsystem-for-linux,Python,Linux,Windows,Ubuntu,Windows Subsystem For Linux,我的电脑上安装了Windows10系统和Ubuntu子系统。 我想在pythonscipt with os.subprocess中执行bash命令,但是如果我的Unix子系统被“仅”设置为子系统,我该怎么做呢? 有什么建议吗?只需在命令前面添加“wsl”。比如说 subprocess.run("wsl pwd", shell=True) 您是在WSL中还是在Windows端运行Python脚本?如果您是在WSL中运行它,它应该像只使用os.subprocess一样简单。

我的电脑上安装了Windows10系统和Ubuntu子系统。 我想在pythonscipt with os.subprocess中执行bash命令,但是如果我的Unix子系统被“仅”设置为子系统,我该怎么做呢?
有什么建议吗?

只需在命令前面添加“wsl”。比如说

subprocess.run("wsl pwd", shell=True)

您是在WSL中还是在Windows端运行Python脚本?如果您是在WSL中运行它,它应该像只使用
os.subprocess
一样简单。