How to execute commands with double quotes (net start "search windows") using ps "os" module?

When I execute a simple command like "net start", I get the output successfully, as shown below.

Python script:

import os def test(): cmd = ' net start ' output = os.popen(cmd).read() print output test() 

Output:

 C:\Users\test\Desktop\service>python test.py These Windows services are started: Application Experience Application Management Background Intelligent Transfer Service Base Filtering Engine Task Scheduler TCP/IP NetBIOS Helper The command completed successfully. C:\Users\test\Desktop\service> 

But when I execute long commands (for example: "net start" search for windows "), I DO NOT get any output.

Python script:

 import os def test(): cmd = ' net start "windows search" ' output = os.popen(cmd).read() print output test() 

Output:

 C:\Users\test\Desktop\service>python test.py C:\Users\test\Desktop\service> 

I tried searching for "net start \" windows \ "". also. But the same problem.

Can anyone participate in this for me?

+5
source share
1 answer

From the documentation :

Deprecated since version 2.6: this feature is deprecated. Use the subprocess module. Especially check out "Replacing Old Functions" in the "Subprocess" section .

 subprocess.Popen(['net', 'start', 'windows search'], ...) 
+3
source

Source: https://habr.com/ru/post/1233476/


All Articles