what is the right format of the cmd command "start"?

AliceDrop 60 Reputation points
2023-11-06T16:46:42.1633333+00:00

Someone told me that if I want to use the cmd command "start" to open a file with a exe application, the format should be like this :" start "" "cai\BB2.swf" "cai\aa1.exe" ".

So I use "os.system("start "" "cai/bb1.swf" "cai/aa1.exe"")" to run it by python. Actually , it works .However ,sometimes a window asking me to find an application will appear instead of the window of "aa1.exe".When I change it into " os.system("start "cai/bb1.swf" "cai/aa1.exe"")" , the aa1.exe started,but it didn't open the bb1.swf.

What's worse, when I opened the folder in powershell and ran this command, it failed like this.

User's image

Then I changed the command into " start "cai/BB2.swf" "cai/aa1.exe" ". It worked properly.

But when I created a .bat file and wrote it down , It did't work. It became fine when I change it back to " start "" "cai/BB2.swf" "cai/aa1.exe" ".

It seemed like running command in cmd / powershell /the os.system( ) function in python can be very different.And the usage of "/"and "",and even the number of argument in the start command veried.

So why? And which is the right format , in the os.system( ) function of python and cmd shell /powershell?

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
6,813 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 29,371 Reputation points
    2023-11-06T18:30:53.0933333+00:00

    You put the program name first and pass the file name as an argument.

    In a command prompt:

    start notepad.exe c:\temp\AdminTest.txt
    start "My window title" notepad.exe c:\temp\AdminTest.txt
    help start 
    
    
    

    In a Powershell prompt:

    start-process notepad.exe C:\temp\AdminTest.txt
    start-process notepad.exe -ArgumentList C:\temp\AdminTest.txt
    get-help start-process
    

    However ,sometimes a window asking me to find an application

    If you try to "start c:\temp\somefile.txt", Windows looks to see what program is associated with .txt files and launches it. You'll get that prompt if there is no program associated with the file extension.

    So I use "os.system("start "" "cai/bb1.swf" "cai/aa1.exe"")" to run it by python.

    Start is a cmd.exe command. There is no start.exe. I don't have Python installed but I would expect one of these options would work. The first example might cause python to hang while aa1.exe is running. You will just have to test.

    os.system("cai/aa1.exe cai/bb1.swf")
    os.system("cmd.exe /c start cai/aa1.exe cai/bb1.swf")
    

    You may also need to specify the full path to the files. (C:\SomeFolder\cai\aa1.exe)

    Python's os module may implement it's own start command. I've seen examples like os.system('date'), which I would normally not expect to work because there is no date.exe program. Again, I don't have python installed to be able to test.

    https://www.w3schools.com/python/module_os.asp

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful