Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.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/5/date/2.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 有没有一种方法可以用bash而不是cmd编译?_Python_Linux_Windows_Bash - Fatal编程技术网

Python 有没有一种方法可以用bash而不是cmd编译?

Python 有没有一种方法可以用bash而不是cmd编译?,python,linux,windows,bash,Python,Linux,Windows,Bash,我正在运行Windows 10,我正在观察运行Linux的人 他正在教授子流程模块,并演示如何通过终端调用命令(在Linux中) 我的问题是Linux的命令与Windows中的命令不同,例如,对于ifconfig,您需要在Windows中调用ipconfig/all 所以我去了微软商店,下载了一个叫做Kali Linux的产品 我的问题是如何在VisualStudio中使用bash而不是cmd 示例: import subprocess # Linux command subprocess.c

我正在运行Windows 10,我正在观察运行Linux的人

他正在教授
子流程
模块,并演示如何通过终端调用命令(在Linux中)

我的问题是Linux的命令与Windows中的命令不同,例如,对于
ifconfig
,您需要在Windows中调用
ipconfig/all

所以我去了微软商店,下载了一个叫做Kali Linux的产品

我的问题是如何在VisualStudio中使用bash而不是cmd

示例:

import subprocess

# Linux command
subprocess.call('ifconfig', shell=True)

# Windows command
subprocess.call('ipconfig /all', shell=True)

Python终端或cmd无法识别
ifconfig
命令。

我假设您安装了Windows Linux子系统(WSL)。有了WSL,您可以在Windows“
cmd
中执行bash。您只需使用其
-c
选项将要在bash中执行的命令传递给
bash
命令:

subprocess.call('bash -c ifconfig', shell=True)
请注意,整个命令必须作为单个参数传递给
bash
。也就是说,如果要执行
ls-l
,必须使用
bash-c“ls-l”

如果要使用多个子进程调用执行多个命令,则必须在每次调用中使用
bash-c
,或更改默认shell(请参阅):

在具有
shell=True
的Windows上,
COMSPEC
环境变量指定默认shell


cmd
命令
其中bash
显示了要将默认shell更改为
bash
必须在
COMPSPEC
中指定的路径。在我的Windows 10系统上,它是
C:\Windows\System32\bash.exe

你考虑过吗?@PM77-1嘿,这不是我要找的。我想用bash而不是cmd编译Python程序。因此,
ifconfig
命令将正确执行,bash将识别它。最简单的方法:首先安装windows软件包管理器
chocolate
(),然后安装cygwin()@PM77-1和Lonely:cygwin与WSL相比有什么优势吗?我不明白为什么当WSL直接内置到Windows中时,Cygwin仍然经常被推荐。