我可以在Windows任务计划程序中执行.SH文件吗?

时间:2013-03-05 06:01:16

标签: windows bash cygwin scheduled-tasks sh

.sh脚本已在cygwin中测试并运行,但现在我希望Windows每小时自动运行一次。

该文件具有可执行权限,现在我在cygwin终端内运行它:

cd c:/users/me/documents/myfile.sh
./myfile.sh

我该怎么做?

谢谢!

2 个答案:

答案 0 :(得分:1)

或通过批处理执行bash

执行:

     call "batch_from_below.bat  "c:\user\me\documents\myfile.sh" "parameter 1, if need" "parameter 2 ..."

批次:

     @echo off
     set _CYGBIN=change-this-to-your-path-cygwin\bin

     if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%"

     REM ------------------------------------------------------------------------
     REM SCRIPT
     REM ------------------------------------------------------------------------
     set x=%1
     set x=%x:\=\\%
     set _CYGPATH_SCRIPT=%_CYGBIN%\cygpath.exe %1
     FOR /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%x%"') do set _SCRIPT=%%A

     REM ------------------------------------------------------------------------
     REM PATH
     REM ------------------------------------------------------------------------
     set _SCRIPT_PATH=%~dp1
     FOR /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%_SCRIPT_PATH%"') do set          _PATH_TO_SCRIPT=%%A

     REM ------------------------------------------------------------------------
     REM EXECUTE
     REM ------------------------------------------------------------------------
     %_CYGBIN%\bash.exe --login -c 'cd %_PATH_TO_SCRIPT%;%_SCRIPT% %2 %3 %4 %5 %6 %7 %8 %9'

答案 1 :(得分:-1)

您需要修改系统环境变量 PATHEXT 以包含 .SH; 作为已知程序文件扩展名,然后将Bash shell文件与 .SH相关联在Windows中(谷歌将是我与之相关的更好的朋友:)。