Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to run an in Ubuntu 18.04 on Windows without spawning a terminal?

Writer Matthew Barrera

I've got Ubuntu 18.04 LTS installed on my Windows 10 machine. Looks like this

and this

just so we're all on the same page.

Now, how can I run an app under bash/ubuntu without having it open a terminal? i.e. no GUI. i.e. headless.

I want to run it using the Windows Task Scheduler

And right now it keeps popping up a window at 9pm which is super annoying.

I can't even find the .exe for Ubuntu 18.04, I guess it's installed through the app store now. I can run my older legacy install from cmd.exe,

% bash.exe -c "lsb_release -a" No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial 

not that that helps me because the scheduler pops up a window for that too.

2

2 Answers

I'll find out in a couple hours if this actually works, but I think it should.

Create a windows task like this:

The script I'm running looks like this:

C:\runHidden.vbs C:\Users\Mark\AppData\Local\Microsoft\WindowsApps\ubuntu1804.exe -c "sudo /usr/local/bin/borgbackup.sh 2>&1 | sudo tee -a /var/log/borg.log | sudo /usr/local/bin/mailgun.sh 2>&1 | sudo tee -a /var/log/mailgun.log"

First arg is the script I'll paste below, second is whatever Linux distro you want to run.

runHidden.vbs is:

' Simple command-line help.
select case WScript.Arguments(0)
case "-?", "/?", "-h", "--help" WScript.echo "Usage: runHidden executable [...]" & vbNewLine & vbNewLine & "Runs the specified command hidden (without a visible window)." WScript.Quit(0)
end select
' Separate the arguments into the executable name
' and a single string containing all arguments.
exe = WScript.Arguments(0)
sep = ""
for i = 1 to WScript.Arguments.Count -1 ' Enclose arguments in "..." to preserve their original partitioning. args = args & sep & """" & WScript.Arguments(i) & """" sep = " "
next
' Execute the command with its window *hidden* (0)
WScript.CreateObject("Shell.Application").ShellExecute exe, args, "", "open", 0

credit mklement0. Can also be found here and probably a dozen other places by now.

Update: This works great when ran from cmd.exe but it doesn't seem to be doing anything when ran from Task Scheduler. It says "Running" but nothing is logging to me log file, so I can't be sure. LMK in the comments if you find a definitive answer.

Found a better solution. No hacks or funny business.

Just use wsl. You can even run apps as root with -u root.

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy