我想知道如何创建批处理文件以在Cygwin上执行Python
尝试了2种方法
方法1:
cd c:\cygwin64\bin
bash --login -i
python /home/xxxxx/snmptest.py
方法2:
cd c:\cygwin64\bin
bash --login -i
/bin/bash.exe /home/xxxxx/snmp.sh
bash文件包含
#!/bin/bash
python /home/xxxxx/snmptest.py
两者都无法运行Python脚本,即只需打开Cygwin窗口。
在方法2中,我可以在Cygwin上成功执行bash文件并运行python脚本。
有关如何完成我的目标的任何想法吗?
由于
答案 0 :(得分:0)
这是我在Windows上运行以执行名为" my_shell_command"的shell脚本的批处理文件。在cygwin中运行:
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
它存储在我的桌面上一个名为" my_shell_command.bash"的文件中。在Windows中我有" bash"扩展名设置为"打开" bash.exe所以我可以双击批处理脚本从Windows执行我的shell脚本。
希望你所有人都需要修改它以便为你工作。