In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to call exe file in os.system in python". In daily operation, I believe that many people have doubts about how to call exe file in os.system in python. The editor has consulted all kinds of information and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to call exe file in python". Next, please follow the editor to study!
First of all, I would like to introduce to you a process of running the software MODTRAN.
To put it simply, modify the parameters in tape5, and then run the Mod4v1r1.exe file to generate the tape6 file. The required data is stored in the tape6 file.
So, the program that modifies the tape5 parameter is written, and all that's left is to call Mod4v1r1.exe to run it. The following code is the python code I tested for os.system ():
Import os # Import os module os.system ('Mod4v1r1.exe') # the environment variables of the exe file have been set here
First explain os.system ('command'). This function is used to execute the cmd command under windows, where command is the cmd command
The result is that the console outputs a line of prompts:
File "tape5" does not exist.
I can't stand this. The tape5 file obviously exists, and it's still in the same directory as the exe file. How can I not find it? I continue to type and run a Mod4v1r1.exe test in the cmd window, and it's the same result.
Then the problem is not python's os.system. To continue to look up information on the Internet, you can use cmd's start command to run the exe file. Its syntax is
Start ["title"] [/ dPath] [/ I] [/ min] [/ max] [{/ separate | / shared}] [{/ low | / normal | / high | / realtime | / abovenormal | belownormal}] [/ wait] [/ b] [FileName] [parameters]
The meaning of its parameters can be used in cmd using 'start/?'' Command to view the relevant help as shown in the figure:
Parameters.
Title specifies the title that is displayed in the title bar of the Command prompt window.
/ dpath specifies the startup directory.
/ I transfers the Cmd.exe startup environment to a new Command prompt window.
/ min starts a new minimization window.
/ max launches a new maximize window.
/ separate starts a 16-bit program in a separate memory space.
/ shared starts a 16-bit program in a shared memory space.
/ low starts the application with an idle priority.
/ normal starts the application with normal priority.
/ high starts the application with high priority.
/ realtime starts the application with real-time priority.
/ abovenormal starts the application in a way that exceeds the normal priority.
/ belownormal starts the application in a way that is lower than the normal priority.
/ wait starts the application and waits for it to finish.
/ b you do not have to open a new Command prompt window when you start the application. CTRL+C operations are ignored unless the application enables CTRL+C. Use CTRL+BREAK to interrupt the application.
A non-executable file can run through its file association as long as the file name is typed as a command. About using assoc and ftype to create in a command script.
When the first command you run is marked with a "CMD" string but does not include an extension or path qualifier, "CMD" is replaced by the value of the COMSPEC variable. This prevents the user from selecting cmd from the current directory.
When you run a 32-bit graphical user interface (GUI) application, cmd does not wait for the application to exit before returning to the command prompt. This new situation does not occur if you run the application from a command script.
When the first symbol in the running command does not include the extension, Cmd.exe uses the value of the PATHEXT environment variable to determine the extension to look for and the search order.
The default value of the PATHEXT variable is: COM;.EXE;.BAT;.CMD (the syntax is the same as the PATH variable, using semicolons to separate different elements). When you search for an executable and there is no match on any extension, start searches for the directory name.
Without taking a closer look at the parameters, I directly use the command in cmd: start "" file path and file name "(empty between the two double quotes after start means that the title of the new command line window opened by running the exe file is empty, if it is not set, it will treat the subsequent file path and file name as title). After running the command, I saw a cmd window flash as if it was running But check that the data in the tape6 file has not changed, so the exe file did not run successfully.
Continue to look at the corresponding parameters and check the information found that in the execution of the command to add the "/ dpath" parameter, set the startup directory, otherwise you can not find the tape5 file, the modified cmd command is: start "" / d "file location directory"exe file name", enter found to run successfully.
But batch processing in python encounters another problem.
In a loop, each time the exe file is executed, the tape6 is output and the data is extracted, but each time the exe program is executed before it is finished, the subsequent python code is executed, so that the data in the tape6 can not be extracted. Continue to look at the parameters of start to see if you can solve the problem.
There is a / wait in the parameter, which is used to start the application and wait for it to finish, so I changed the python code to os.system (the directory where the 'start "" / d "file is located" / wait "exe file name")
The program was executed successfully and the data in tape6 was extracted successfully.
At this point, the study on "how to call the exe file in os.system in python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.