In the effort to bring some of the Linux advantages to my customers running Windows 10, I've developed a few bash scripts in order to automate some of their everyday tasks.
I use to let them run the scripts through a Windows batch with the following content:
Ubuntu1804 run /usr/local/bin/script.sh
Unfortunately some of the scripts are taking long, either for huge sql queries or slow net and I/O operations, and during this wait a few users just can't refrain from closing the "strange black window", thus killing the process.
The command above will be killed even if put in quotes with & at the end.
I tried the following and didn't get testOK
on my desktop.
Ubuntu1804 run "sleep 10 && touch /mnt/c/Users/myuser/Desktop/testOK &"
While this keeps the window open and creates the file testOK
instead.
Ubuntu1804 run "sleep 10 && touch /mnt/c/Users/myuser/Desktop/testOK"
I was wondering if there is a way to avoid the process in Ubuntu WSL to be killed as soon as the window is closed.
Prevent the window to appear at all would be great too.
Prevent the user to interact with it would be an acceptable workaround.
Clients are Windows 10 Professional with latest security and quality rollup, I'm not providing site details since this is happening at more than one customer, some of them are big MS AD domains, some other are small offices with just a workgroup.
Linux X11 sends a SIGHUP to running processes that have a file handle open to the terminal window when the terminal window closes. All programs by default have stdin, stdout, and stderr file handles open to the terminal window that spawned the program. WSL emulates that behavior.
One solution is to use 'nohup'. If test.sh is:
Then you can run it like this:
If I immediately close the cmd window after typing that line, I get a file "nohup.out" in D: (my current working directory) that has the text generated by test.sh, and a few seconds later get testOK in my Ubuntu home directory. You can change things around inside your .bat script to put the nohup.out somewhere else though.
You can create a .vbs file like so:
The last line, the "0" means don't show a window, "1" would mean show window.
I think this should accomplish what you are trying to do.