| | |
Running a 3rd party program from Python
![]() |
Hai friends
I have a some trouble in running a 3rd party program. This 3rd party program actually takes one file as input & does some processing on it and creates an output in a different folder with the same name, but with different file extention. I do it manually from DOS prompt. I automated this by using the following code
When I execute this command manully in the DOS prompt, I get a (y/n) input, for which I usually give 'y'. But when the Python script executes it, the script stops to ask for the (y/n)input for each file. I want Python script itself to give 'y' as default input, without prompting for each file.
Is there anyway this can be done?
I have a some trouble in running a 3rd party program. This 3rd party program actually takes one file as input & does some processing on it and creates an output in a different folder with the same name, but with different file extention. I do it manually from DOS prompt. I automated this by using the following code
Python Syntax (Toggle Plain Text)
import os import sys for filename in os.listdir('d:\path2\subpath2'): if filename.find('.txt') >= 0: f1 = filename.split('.') print f1,filename x = "d:\\path1\\subpath1\\gpg -r encr -o d:\\dest1\\subdest\\" + f1[0] + ".txt.gpg -e d:\\path2\\subpath2\\" + filename os.system(x)
When I execute this command manully in the DOS prompt, I get a (y/n) input, for which I usually give 'y'. But when the Python script executes it, the script stops to ask for the (y/n)input for each file. I want Python script itself to give 'y' as default input, without prompting for each file.
Is there anyway this can be done?
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
I am not familiar with that command, but would using the --batch option help. I think that would allow it to not ask for any user input
just a thought about your code. If you are checking for the file extention ".txt" using the string method endswith might be a better choice.
or to shorten it up this means the same as is True
Python Syntax (Toggle Plain Text)
x = "d:\\path1\\subpath1\\gpg --batch -r encr -o d:\\dest1\\subdest\\" + f1[0] + ".txt.gpg -e d:\\path2\\subpath2\\" + filename
just a thought about your code. If you are checking for the file extention ".txt" using the string method endswith might be a better choice.
Python Syntax (Toggle Plain Text)
if filename.endswith('.txt') == True:
or to shorten it up this means the same as is True
Python Syntax (Toggle Plain Text)
if filename.endswith('.txt'):
In a perfect world exceptions would not be needed.
Well 'gpg' is actually not a DOS command. Its like a command line encryptor. It does some operation on the file which I am not aware of... It doesnt support the --batch option, I checked that out.
I do it manually like this ....
So as you see, for each & every file it asks for such a confirmation, when using the python code. I want to answer a default 'y' from the code itself.
I do it manually like this ....
Python Syntax (Toggle Plain Text)
d:\path1\subpath1>gpg -r encr -o d:\dest1\subdest\sample.txt.gpg -e d:\path2\subpath2\sample.txt Are you sure you want to encrypt(y/n)? y Encrypted... d:\path1\subpath1>
So as you see, for each & every file it asks for such a confirmation, when using the python code. I want to answer a default 'y' from the code itself.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
On my linux system the batch option seems available. here is from the gpg manual page
maybe the version you are using could be different.
I do not think you can use python to answer 'y or n' for you. I am pretty much a novice, so I may be worng. let me know if you figure out a solution
•
•
•
•
--batch
Use batch mode. Never ask, do not allow interactive commands
I do not think you can use python to answer 'y or n' for you. I am pretty much a novice, so I may be worng. let me know if you figure out a solution
In a perfect world exceptions would not be needed.
•
•
Join Date: May 2005
Posts: 215
Reputation:
Solved Threads: 16
If this option is available for you, this MAY work.
below is what I read in the manual page
Python Syntax (Toggle Plain Text)
d:\path1\subpath1>gpg --command-fd y -r encr -o d:\dest1\subdest\sample.txt.gpg -e d:\path2\subpath2\sample.txt
below is what I read in the manual page
•
•
•
•
--command-fd n
This is a replacement for the depreciated shared-memory IPC mode. If this option is enabled, user input on questions is not expected from the TTY but from the given file descriptor. It should be used together with --status-fd. See the file doc/DETAILS in the source distribution for details on how to use it
In a perfect world exceptions would not be needed.
Hai
Sorry for replying so late...
I tried the one which you suggested, but the Windows version of gpg seems to be entirely different.
I was looking into win32pipe & win32process modules, which enables to pass parameters... The popen or spawnl fuctions of win32pipe ( since os.popen doesnt work fine with Windows) could do some help it seems ... But I am not exactly sure how they work... had a very hard time understanding them...couldn't find any simple examples to start with...
And I felt I would better simplify my problem, it seems the example code I had given previously is a little too long...
Its like, Say I have an .exe file in one of my folders, which can be executed only from DOS. The work would look like...
C:\somefolder\myprg.exe
Enter Ticket: 123456
Enter Filname : file1
File Created....
C:\somefolder\>
The parameters in red are typed manually...
myprg.exe does not take arguments in command line, instead they can be given only during the time of execution...
I can fetch the values by using the python code, but I have no idea how to pass it in the above case...it seems win32pipe can do the trick, but couldnt find any examples helpful enough...
Any help on this with an example would be greatly helpfull.... :rolleyes:
Sorry for replying so late...
I tried the one which you suggested, but the Windows version of gpg seems to be entirely different.
I was looking into win32pipe & win32process modules, which enables to pass parameters... The popen or spawnl fuctions of win32pipe ( since os.popen doesnt work fine with Windows) could do some help it seems ... But I am not exactly sure how they work... had a very hard time understanding them...couldn't find any simple examples to start with...
And I felt I would better simplify my problem, it seems the example code I had given previously is a little too long...
Its like, Say I have an .exe file in one of my folders, which can be executed only from DOS. The work would look like...
C:\somefolder\myprg.exe
Enter Ticket: 123456
Enter Filname : file1
File Created....
C:\somefolder\>
The parameters in red are typed manually...
myprg.exe does not take arguments in command line, instead they can be given only during the time of execution...
I can fetch the values by using the python code, but I have no idea how to pass it in the above case...it seems win32pipe can do the trick, but couldnt find any examples helpful enough...
Any help on this with an example would be greatly helpfull.... :rolleyes:
![]() |
Similar Threads
- internet explorer won't work SOMETIMES (Web Browsers)
- ...you guessed it, the dreaded C000021a {Fatal System Error} (Windows NT / 2000 / XP)
- URGENT HELP NEEDED - critically important...!!! (Windows NT / 2000 / XP)
- starting 3rd party programs (VB.NET)
Other Threads in the Python Forum
- Previous Thread: Compiling .py files...
- Next Thread: Sound in Python
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book builtin calculator change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event file float format function google homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin prime programming py2exe pygame pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython





