![]() |
| ||
| 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 import os 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? |
| ||
| Re: Running a 3rd party program from Python 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 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. if filename.endswith('.txt') == True:or to shorten it up this means the same as is True if filename.endswith('.txt'): |
| ||
| Re: Running a 3rd party program from Python 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 .... d:\path1\subpath1>gpg -r encr -o d:\dest1\subdest\sample.txt.gpg -e d:\path2\subpath2\sample.txt 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. |
| ||
| Re: Running a 3rd party program from Python On my linux system the batch option seems available. here is from the gpg manual page Quote:
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 |
| ||
| Re: Running a 3rd party program from Python If this option is available for you, this MAY work. 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 Quote:
|
| ||
| Re: Running a 3rd party program from Python 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: |
| All times are GMT -4. The time now is 7:08 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC