2
.sh腳本經過測試並在cygwin中工作,但現在我想讓Windows每小時自動運行一次。我可以在Windows任務計劃程序中執行.SH文件嗎?
該文件具有可執行權限,現在我運行像這樣的cygwin的終端裏面:
cd c:/users/me/documents/myfile.sh
./myfile.sh
我應該怎麼辦呢?
謝謝!
.sh腳本經過測試並在cygwin中工作,但現在我想讓Windows每小時自動運行一次。我可以在Windows任務計劃程序中執行.SH文件嗎?
該文件具有可執行權限,現在我運行像這樣的cygwin的終端裏面:
cd c:/users/me/documents/myfile.sh
./myfile.sh
我應該怎麼辦呢?
謝謝!
您需要修改系統環境變量PATHEXT也包含.SH;作爲已知的程序文件擴展名,然後在Windows中將Bash shell文件與.SH相關聯(Google將成爲我更好的朋友:)。
,或通過批處理
執行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'
的[你如何在Windows上運行在Cygwin的一個crontab?](HTTP
可能重複: //stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin-on-windows) – 2013-03-05 08:19:29