2

Let's say I have WSL Ubuntu installed. Now I want to finish the following tasks by a batch file:

  • run Ubuntu in cmd

  • run Python in Ubuntu

  • run Python commands under interactive mode

I've tried batch files such as

cmd /k ubuntu "python"

and

cmd /k ubuntu
python

...

Unfortunately, all failed to run python in WSL.

What should I do to run commands in such "nested environments"?

3
  • Have you tried cmd /k ubuntu -c python? Or just cmd /k wsl python? (Assuming Ubuntu is your default). May 26, 2020 at 12:15
  • @Anaksunaman I just tried them out and they work! You may want to consider adding an answer and I will accept it then. Also, I found nothing about -c in Microsoft docs. Could you please provide me a link or something so that I can read more details?
    – kakakali
    May 26, 2020 at 13:49
  • I have added a short answer. =) May 31, 2020 at 3:57

1 Answer 1

2

Assuming Ubuntu is your default Linux distribution under WSL, you should try using either cmd /k ubuntu -c python or simply cmd /k wsl python.

If you would like to read more about using WSL with cmd, you may want to take a look at these articles:

The first article has examples of how to execute commands via WSL in cmd at the end of the post, while the second article confirms that the -c option isn't required for wsl:

[The] -c option for running a single command isn't needed with wsl.exe.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .