Page 1 of 1

The PC shuts down before the scripts finish

Published: August 2, 2017 - 2:23 PM
by Root
Good morning,
I use a Python script to launch other scripts (often batch or ps1 files).
In my package, setup.py ends with the instruction:

Code: Select all

os.system("cd C:\dossier0\dossier1 && start setup.bat")
In my bat I launch commands wmic (uninstall) and I use other functions which may take some time to complete.

My question is: How can I prevent Wapt from shutting down the computer before the batch process is complete? How can I make Wapt understand that the job isn't finished and that it needs to wait before shutting down?

I thought about using `time.sleep(10)`... but well, it's not very... clean :ugeek: Furthermore, the script does not take the same amount of time on each machine.

By the way:
I discovered WAPT during my studies while looking for deployment software; I use it on my personal computer and, since this year, in the company where I work! It's an excellent product.
I would also like to know where I can report problems related to my packages or my usage.

EDIT: Oops, wrong forum

Re: PC shuts down before scripts finish

Published: August 2, 2017 - 5:20 PM
by agauvrit
Topic moved.

Regarding your question: https://www.wapt.fr/fr/doc/Frequent-pro ... tput-600-0

For your function, you could write it like this:

Code: Select all

os.chdir(r"C:\dossier0\dossier1")
run("setup.bat",timeout=1200)
Good package development!

Re: PC shuts down before scripts finish

Published: August 3, 2017 - 09:13
by Root
agauvrit wrote: August 2, 2017 - 5:20 PM Topic moved.

Regarding your question: https://www.wapt.fr/fr/doc/Frequent-pro ... tput-600-0

For your function, you could write it like this:

Code: Select all

os.chdir(r"C:\dossier0\dossier1")
run("setup.bat",timeout=1200)
Good package development!
Good morning,
Thanks for the reply. I'll try your solution in the next update of my package.

I'm considering abandoning batch processing and rewriting my script in Python, but I'm afraid I'll encounter the same problem if I end my Python script with:
os.popen('wmic product where name="SoftwareName" call uninstall')
Good day

Re: PC shuts down before scripts finish

Published: August 4, 2017 - 10:25
by swbsf
Hi,
I use it successfully:

Code: Select all

        cmd="c:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File c:\\tmp\\Win10.ps1"
        proc = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
        proc.wait()
The `proc.wait()` function works well in my case, as it also reboots the machine at the end of the process. You must, of course, import `subprocess`. And replace `cmd` with your command, whatever it may be.
The timeout=xxx solution is flawed; it's ideal for.. race condition.

Re: PC shuts down before scripts finish

Published: August 10, 2017 - 11:43
by Root
swbsf wrote: August 4, 2017 - 10:25 Hi,
I use it successfully:

Code: Select all

        cmd="c:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File c:\\tmp\\Win10.ps1"
        proc = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
        proc.wait()
The `proc.wait()` function works well in my case, as it also reboots the machine at the end of the process. You must, of course, import `subprocess`. And replace `cmd` with your command, whatever it may be.
The timeout=xxx solution is flawed; it's ideal for.. race condition.
Thanks, I tried it with proc.wait() and it works fine