Running a 3rd party program from Python

Reply

Join Date: Aug 2005
Posts: 46
Reputation: xav.vijay is an unknown quantity at this point 
Solved Threads: 6
xav.vijay's Avatar
xav.vijay xav.vijay is offline Offline
Light Poster

Running a 3rd party program from Python

 
0
  #1
Nov 15th, 2005
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

  1. import os
  2. import sys
  3. for filename in os.listdir('d:\path2\subpath2'):
  4. if filename.find('.txt') >= 0:
  5. f1 = filename.split('.')
  6. print f1,filename
  7. x = "d:\\path1\\subpath1\\gpg -r encr -o d:\\dest1\\subdest\\" + f1[0] + ".txt.gpg -e d:\\path2\\subpath2\\" + filename
  8. 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?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Running a 3rd party program from Python

 
0
  #2
Nov 15th, 2005
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
  1. 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.
  1. if filename.endswith('.txt') == True:

or to shorten it up this means the same as is True
  1. if filename.endswith('.txt'):
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 46
Reputation: xav.vijay is an unknown quantity at this point 
Solved Threads: 6
xav.vijay's Avatar
xav.vijay xav.vijay is offline Offline
Light Poster

Re: Running a 3rd party program from Python

 
0
  #3
Nov 16th, 2005
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 ....

  1. d:\path1\subpath1>gpg -r encr -o d:\dest1\subdest\sample.txt.gpg -e d:\path2\subpath2\sample.txt
  2.  
  3. Are you sure you want to encrypt(y/n)? y
  4.  
  5. Encrypted...
  6.  
  7. 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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Running a 3rd party program from Python

 
0
  #4
Nov 16th, 2005
On my linux system the batch option seems available. here is from the gpg manual page
--batch

Use batch mode. Never ask, do not allow interactive commands
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
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: Running a 3rd party program from Python

 
0
  #5
Nov 16th, 2005
If this option is available for you, this MAY work.
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 46
Reputation: xav.vijay is an unknown quantity at this point 
Solved Threads: 6
xav.vijay's Avatar
xav.vijay xav.vijay is offline Offline
Light Poster

Re: Running a 3rd party program from Python

 
0
  #6
Nov 19th, 2005
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:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC