schedule running a bash shell script in windows

╄→гoц情女王★ 提交于 2019-11-27 16:20:49

A solution is to associate .sh files with a batch file that runs bash. That way whenever you tell windows to execute an sh file it'll use the correct launcher - whether that's via a double click or a scheduled task. Here's mine:

@echo off

d:
chdir d:\cygwin\bin

bash --login %*

Associating a file type means that when you try to execute a file of that type, windows will use the path to that file as an argument passed to the program you've specified. For example, I have LibreOffice4 associated with .ods files. So if I doubleclick a .ods file, or just enter the path to a .ods file at the command prompt, windows will run open office calc, with the first parameter being the ods file. So if I have Untitled.ods on my desktop. I doubleclick it. That's effectively the same as opening up command prompt, typing

D:\Program Files (x86)\LibreOffice 4\program\scalc.exe" "C:\Users\Adam\Desktop\Untitled.ods".

and hitting enter. Indeed, if I do it, the expected happens: open office calc starts up and loads the file.
You can see how this works if you change the association to echo.exe (which I found in D:\cygwin\bin). If I change the association to echo, open up the command prompt and type

"C:\Users\Adam\Desktop\Untitled.ods"

I'll just see echo.exe echo the filename back to me.

So what I'm suggesting you do is this:

  1. create a batch file to run bash scripts using cygwin's bash (or use mine).
  2. change the association for .sh files to that batch file
  3. execute those .sh files directly, as though they were .exe or .bat files.

why not creating a batchfile (.bat) that loads your cygwin bashscript and schedule this batchfile? like this you dont have to deal with the way M$ handles paramters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!