1

I'm learning how to create an automatic script in python (3.7) and I've noticed of these different behaviours:

(The python script is not relevant in this question but it works quite well so that I'm sure the answer of my question isn't here).

  • Case 1:

    I create a batch file "test.bat" with this content:

    test.bat

    START "test" "C:\Users\cooper\AppData\Local\Programs\Python\Python37-32\test\v4.py" 
    

    I execute it (double click) and it opens a first window and right after closes it, and just after opens a second window with the title: "C:\Windows\py.exe" and the python script works well.

  • Case 2:

    I create a cronjob on the cron task scheduler with an action to execute the batch file.

    The cronjob is the standart one:

    • Trigger: on a specific time, execute it X times in a day
    • Action: execute the batch file
    • I also changed an option called: configuration (W10 in my case).

    When the file is executed it opens the first window and immediately after closes it, and just after it opens the second window and immediately after close it.

I would like to run the python script but doing it through the cronjob but whatever I do, it doesn't work. I've tried other variations on the batch file using cd and directly using:

"C:\Users\cooper\AppData\Local\Programs\Python\Python37-32\python.exe" "C:\Users\cooper\AppData\Local\Programs\Python\Python37-32\test\v4.py"

but none of them works. Idon't remember well the first, but the second shows command line on System32 directory and doing nothing.

cooper
  • 635
  • 1
  • 8
  • 23
  • Have your read the output from `start /?`? If so, did you try it with the `/B` option? – Compo May 08 '19 at 20:46
  • There's no enough time to read it. The window stay opened like...0.3s?? So that it's impossible to read it. I also tried the "/B" option but the result is exactly the same – cooper May 09 '19 at 18:12
  • The command will be run and when there's nothing left to do, it will close. Add another line, with `Pause` or `Timeout 5` to read the output before it closes. – Compo May 09 '19 at 19:19

1 Answers1

0

The /K option did the trick

"C:\Users\cooper\AppData\Local\Programs\Python\Python37-32\python.exe" "C:\Users\cooper\AppData\Local\Programs\Python\Python37-32\metart\v4.py" /K
cooper
  • 635
  • 1
  • 8
  • 23