Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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
C Windows shell命令中嵌入的Python代码_C_Windows_Python 2.7_Command Line_Arguments - Fatal编程技术网

C Windows shell命令中嵌入的Python代码

C Windows shell命令中嵌入的Python代码,c,windows,python-2.7,command-line,arguments,C,Windows,Python 2.7,Command Line,Arguments,如何将一个小Python脚本嵌入到Windows shell命令中,为程序提供参数 例如: C:\> hello Bob Welcome Bob! 我需要的是这样的东西: C:\> hello 'python -c print('Bob')' Welcome Bob! 谢谢 Powershell支持与bash相同的格式,因此您可以执行以下操作: PS C:\> hello $(python -c "print('Bob')") 对于cmd.exe,没有此类等效项,但您可以

如何将一个小Python脚本嵌入到Windows shell命令中,为程序提供参数

例如:

C:\> hello Bob
Welcome Bob!
我需要的是这样的东西:

C:\> hello 'python -c print('Bob')'
Welcome Bob!

谢谢

Powershell支持与bash相同的格式,因此您可以执行以下操作:

PS C:\> hello $(python -c "print('Bob')")
对于
cmd.exe
,没有此类等效项,但您可以尝试以下方法(未经测试):


很好!谢谢
C:\>FOR /F "usebackq" %x in (`python -c "print('Bob')"`) DO hello %x