Re: Running Command Prompt In Python
Alan Gauld via Tutor <[email protected]> Thu, 29 Feb 2024 21:52:06 +0000
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <[email protected]> |
On 29/02/2024 11:26, Am Ra wrote: > Importing os, and using os.system to connect to Command Prompt. os.system is nearly always the wrong approach. os.system is really only worthwhile if its a simple throwaway command. For example I use it for an app that manages a list of images and I have a Show menu option that displays the image in the systems file viewer. os.system is fine for that. But for anything where you want to either interact with the command or to view its output you should use subsystem. Either Popen or one of its utility functions. > [image: image.png] The server strips binary files for security reasons, please cut 'n paste the text directly into the email. > Then, dmel922.exe will be activated to generate an empty csv file from a > raw dataset. If it's really empty would it not be simpler to just create it directly from Python? Or is there more going on in the background? > Up to here it is working as it is supposed to. However, it goes on a pause > and not adding any data to the empty csv file... Ah, OK that was only half the story! :-) > ...because it is waiting on the > user input which is “Enter y to Continue”. As we see in the picture below, > the Command Prompt is asking the user to press y to continue. As soon as, I > press y in the Command Prompt it will continue and finish the task. Subprocess is your friend in this scenario. Read the module docs carefully, they are quite detailed and include several examples. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor