After setting up a cron job, I am trying to: automatically enable cron service when I open the Windows Subsystem for Linux Ubuntu 16.04 app from the Windows App Store.
Currently I am trying to reach that goal by simulating:
- Open WSL Ubuntu
- enter
sudo service cron start
<enter>
To do that, I located the ubuntu1604.exe, made myself owner and gave myself permission to read write and open the ubuntu1604.exe.
Next, I openend cmd
in administrator mode, browsed to: C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_1604.2018.510.0_x64__79rhkp1fndgsc
and entered: ubuntu1604.exe
to verify I was able to open WSL ubuntu from cmd without being prompted anything. I was, since it just opened Ubuntu in the same cmd
window (visible thanks to the green <user>@<pcname>:~$
displayed in the cmd
).
Next I tried to pass an argument to the WSL Ubuntu whilst opening it with:
ubuntu1604.exe run echo "hello world"
ubuntu1604.exe echo "hello world"
ubuntu1604.exe -c echo "hello world"
ubuntu1604.exe -c
However:
- Returns
hello world
but does not open WSL ubuntu. - Returns a form of documentation on how to Launch a Linux distribution (attached in picture below).
- Returns
hello world
but does not open WSL ubuntu. - Opens Ubuntu in the location of the current cmd path, but does not execute
So then I tried to open it from a batch script or powershell script with:
- Batch script
test1.bat
:
start /d "C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_1604.2018.510.0_x64__79rhkp1fndgsc" ubuntu1604.exe echo "hello world"
Batch script:
test2.bat
Process.Start("C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_1604.2018.510.0_x64__79rhkp1fndgsc\ubuntu1604.exe", "echo "hello world"");
Powershell script:
test3.ps1
Process.Start("C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_1604.2018.510.0_x64__79rhkp1fndgsc\ubuntu1604.exe", "echo "hello world"");
- Powershell script:
test4.ps1
Process.Start("C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu16.04onWindows_1604.2018.510.0_x64__79rhkp1fndgsc\ubuntu1604.exe", echo "hello world");`
Though:
- Opens a big black screen and closes in a flicker.
- Process.Start is not recognized as an internal or external command
- Is not in powershell language
- Is not in powershell language.
Now I am aware perhaps the option to pass any argumen that can execute a command without user interaction upon startup of the WSL ubuntu1604 might be disabled since it is an app of the app store (or for any other reason).
Hence:
- If anyone knows whether my syntax is correct but my intention
will not be possible this way, please let me know. - If it is possible but I am doing it wrong, I would appreciate any feedback on what I am doing wrong, or a solution that does it right.