How to execute commands with double quotes (net start "windows search") using python 'os' module?
Question: When I execute simple command like "net start", I am getting 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 "windows search") I
am **NOT** getting 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 have tried "net start \"windows search\" ". also. But same issue.

Can anyone guide me on this please?


Answer: From [the documentation](https://docs.python.org/2/library/os.html#os.popen):

> _Deprecated since version 2.6:_ This function is obsolete. Use the
> [`subprocess`](https://docs.python.org/2/library/subprocess.html#module-
> subprocess) module. Check especially the [_Replacing Older Functions with
> the subprocess
> Module_](https://docs.python.org/2/library/subprocess.html#subprocess-
> replacements) section.
    
    
    subprocess.Popen(['net', 'start', 'windows search'], ...)
    

