schedule running a bash shell script in windows

前端 未结 2 1900
一个人的身影
一个人的身影 2020-12-04 03:14

Apreciate any help and excuse me if my terminology is incorrect.

this is a script(*.sh file) that:
1-goes to a specific dir A
2-copies files from another dir

相关标签:
2条回答
  • 2020-12-04 03:48

    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

    0 讨论(0)
  • 2020-12-04 03:55

    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.
    0 讨论(0)
提交回复
热议问题