[英]Run python on Cygwin using batch file
I would like to know how to create a batch file to execute Python on Cygwin please 我想知道如何创建一个批处理文件以在Cygwin上执行Python
Tried 2 methods 尝试2种方法
Method 1: 方法1:
cd c:\cygwin64\bin
bash --login -i
python /home/xxxxx/snmptest.py
Method 2: 方法2:
cd c:\cygwin64\bin
bash --login -i
/bin/bash.exe /home/xxxxx/snmp.sh
The bash file contains bash文件包含
#!/bin/bash
python /home/xxxxx/snmptest.py
Both fails to run the Python script ie just opens the Cygwin window. 两者均无法运行Python脚本,即仅打开Cygwin窗口。
In Method 2, I could successfully execute the bash file on Cygwin and get the python script running. 在方法2中,我可以在Cygwin上成功执行bash文件,并使python脚本运行。
Any thoughts on how to accomplish what I am after please? 关于如何实现我的追求有什么想法吗?
Thanks 谢谢
Here's a batch file that I run on Windows to execute a shell script named "my_shell_command" that runs in cygwin: 这是我在Windows上运行的批处理文件,用于执行名为cygwin的shell脚本“ my_shell_command”:
export HOME="/cygdrive/c/cygwin64/home/$USERNAME"
export PATH="$HOME/bin:/usr/bin:$PATH"
. .bash_profile
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
dir="C:${dir#/cygdrive/c}"
my_shell_command
if (( $? == 0 ))
then
sleep 2
else
echo "" >&2
echo "Hit \"Enter\" when done reading the above error/warning messages." >&2
read resp
fi
It is stored on my desktop in a file named "my_shell_command.bash" and in Windows I have the "bash" extension set to "Open With" bash.exe so I can just double click on the batch script to execute my shell script from Windows. 它存储在我的桌面上名为“ my_shell_command.bash”的文件中,在Windows中,我将“ bash”扩展名设置为“ Open With” bash.exe,因此我可以双击批处理脚本以从中执行我的shell脚本视窗。
Hopefully that's all you'll need to modify it to work for you. 希望这就是您需要修改的所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.