简体   繁体   中英

Python os.system “start” command not found while running through cygwin

I have python installed in C:\\Python27. Also, I have cygwin installed with Python package. In cygwin64 terminal when I do "which python" it gives /usr/bin/python.

Now from command prompt when I run a simple python script:

#!/usr/bin/env/python

import os
os.system("start notepad.exe")

Notepad starts running.

But from Cygwin64 terminal when I do python run.py it throws an error: "sh: start: command not found"

What might be the reason? I have made the python script executable by chmod +x run.py through cygwin terminal. But that did not help.

Thanks for your support.

This isn't a Python question but Cygwin-related. Cygwin doesn't itself have the start command. That's a buitlin of cmd.exe if I recall correctly.

When you're in Cygwin, you're basically in a Unix environment. That means that

os.system("notepad.exe")

should be enough. The pre-requisite is that your PATH environment is set up correctly and includes the Windows directory where notepad.exe resides; for example /c/windows or /c/winnt .

You can do a dry-run of all this by just starting your Cygwin window (with a Bash process) and typing notepad.exe . If it starts, you're OK. Similarly when in Bash, if you type start notepad.exe then (again) the shell will say: start: command not found .

You need not type Start.

This can be done in the following way.

import os os.system("Notepad.exe")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM