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
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?

Recommended Answers

All 5 Replies

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'):

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

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.

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

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

--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

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.