2014-11-03 51 views
0

輸入命令我想寫其中,以下是我想它的工作就像它會打開蟒蛇命令行工具和執行命令批處理文件中的提示

python 
print "hello" 

一個bat文件

print "hello" 

如果以上兩個命令都寫在bat文件 蟒蛇命令行工具是越來越打開,等待後,我手動終止它,接下來的命令得到執行
有沒有什麼辦法讓我可以重定向上述打印「你好」命令進入蟒蛇命令行工具

我知道我們可以寫與打印「你好」一個單獨的Python文件並直接調用,通過
蟒蛇filename.py
但我的要求是明確的重定向這我上面提到

在這方面的任何幫助,非常感謝
在此先感謝!

回答

0

我相信你需要使用python -c命令,然後是你想要執行的代碼。 代碼需要用引號或雙引號括起來(我相信這取決於您是否希望使用多行命令)。

0

嘗試蟒蛇-c打印 「你好」

從文檔:

-c <command>

Execute the Python code in command. command can be one or more statements separated by newlines, with significant leading whitespace as in normal module code. 

If this option is given, the first element of sys.argv will be "-c" and the current directory will be added to the start of sys.path (allowing modules in that directory to be imported as top level modules). 

https://docs.python.org/2/using/cmdline.html

0

你爲什麼不從動態創建一個臨時文件py BAT?

@echo off 
set $Command=print "hello" 
echo %$command% >temp.py 
python temp.py 
del temp.py 
echo next 
pause & exit /b