How do I execute dos command without a path

P

PAPutzback

The process and execute methods want a path to the executable otherwise
they kick out a file not found. So how can I execute the following. It
works fine from a command window.

echo password| gpg.exe --yes --output c:\working\inbound\test.txt
--passphrase 0 -d c:\working\inbound\anstest.gpg
 
C

C-Services Holland b.v.

PAPutzback said:
The process and execute methods want a path to the executable otherwise
they kick out a file not found. So how can I execute the following. It
works fine from a command window.

echo password| gpg.exe --yes --output c:\working\inbound\test.txt
--passphrase 0 -d c:\working\inbound\anstest.gpg

change your current dir to the dir where gpg.exe is residing.
 
H

Herfried K. Wagner [MVP]

PAPutzback said:
The process and execute methods want a path to the executable otherwise
they kick out a file not found. So how can I execute the following. It
works fine from a command window.

echo password| gpg.exe --yes --output c:\working\inbound\test.txt
--passphrase 0 -d c:\working\inbound\anstest.gpg

Are you sure you specified everything after "pgp.exe" in the
'ProcessStartInfo''s 'Arguments' property instead of appending it to the
'FileName' property?
 
P

PAPutzback

Herfried said:
Are you sure you specified everything after "pgp.exe" in the
'ProcessStartInfo''s 'Arguments' property instead of appending it to the
'FileName' property?

No arguments -Error: cannot find file specified
System.Environment.CurrentDirectory = "c:\gnupg"
GPGProcess.StartInfo.WorkingDirectory = "c:\gnupg"
GPGProcess.StartInfo.FileName = "echo little boy blue| gpg"
GPGProcess.StartInfo.CreateNoWindow = True
GPGProcess.StartInfo.UseShellExecute = False
GPGProcess.Start()

No space between pipe and the exectuble = same error

Add .exe = same error

Add the full path "echo little boy blue| c:\gnupg\gpg.exe" = same error

Paste this into a cmd window

C:\gnupg>echo little boy blue| c:\gnupg\gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

I know the command is valid and this variation works also
C:\gnupg>echo little boy blue| gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

And also
C:\gnupg>echo little boy blue| gpg
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

Put the arguments on
C:\gnupg>echo little boy blue| gpg --passphrase-fd 0 -d c:\gnupg\anstest.gpg
Reading passphrase from file descriptor 0

You need a passphrase to unlock the secret key for
user: "Indiana Prohealth <[email protected]>"
1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07 (main key ID FA28FB8B)

gpg: encrypted with 1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07
"Indiana Prohealth <[email protected]>"
This is a test of the emergency broadcast system...

BEEEEEEEEEEEEEEEEEEEEEEEPPPPPPPPPPPPPPPPPP!!!!!

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

And it all works.

Is there not a straight up way to fire off a command like you were in
the command window?

I appreciate your help with this because I am really stressed about
this. It is the final link in an app I need to finish.
 
P

PAPutzback

PAPutzback said:
No arguments -Error: cannot find file specified
System.Environment.CurrentDirectory = "c:\gnupg"
GPGProcess.StartInfo.WorkingDirectory = "c:\gnupg"
GPGProcess.StartInfo.FileName = "echo little boy blue| gpg"
GPGProcess.StartInfo.CreateNoWindow = True
GPGProcess.StartInfo.UseShellExecute = False
GPGProcess.Start()

No space between pipe and the exectuble = same error

Add .exe = same error

Add the full path "echo little boy blue| c:\gnupg\gpg.exe" = same error

Paste this into a cmd window

C:\gnupg>echo little boy blue| c:\gnupg\gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

I know the command is valid and this variation works also
C:\gnupg>echo little boy blue| gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

And also
C:\gnupg>echo little boy blue| gpg
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

Put the arguments on
C:\gnupg>echo little boy blue| gpg --passphrase-fd 0 -d
c:\gnupg\anstest.gpg
Reading passphrase from file descriptor 0

You need a passphrase to unlock the secret key for
user: "Indiana Prohealth <[email protected]>"
1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07 (main key ID FA28FB8B)

gpg: encrypted with 1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07
"Indiana Prohealth <[email protected]>"
This is a test of the emergency broadcast system...

BEEEEEEEEEEEEEEEEEEEEEEEPPPPPPPPPPPPPPPPPP!!!!!

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

And it all works.

Is there not a straight up way to fire off a command like you were in
the command window?

I appreciate your help with this because I am really stressed about
this. It is the final link in an app I need to finish.

Now without the echo command
System.Environment.CurrentDirectory = "c:\gnupg"
GPGProcess.StartInfo.WorkingDirectory = "c:\gnupg"
GPGProcess.StartInfo.FileName = "gpg.exe"

GPGProcess.StartInfo.CreateNoWindow = True
GPGProcess.StartInfo.UseShellExecute = False
GPGProcess.Start()

No errors and the gpg process is running in Task manager

With the arguments
GPGProcess.StartInfo.Arguments = "--yes --output c:\gnupg\test.txt
--passphrase-fd 0 < c:\gnupg\gpg\password.txt --decrypt
c:\gnupg\anstest.gpg"

It is running in task manager but it did not create the file

If I change GPGProcess.StartInfo.CreateNoWindow = false
I get this and it just hangs there.
Reading passphrase from file descriptor 0 ...


If I change the arguments to
GPGProcess.StartInfo.Arguments = "--yes --output c:\gnupg\test.txt
--decrypt c:\gnupg\anstest.gpg"

I get the passphrase prompt

If I add
GPGProcess.StartInfo.RedirectStandardInput = True
GPGProcess.Start()
GPGProcess.StandardInput.Write("little boy blue")
GPGProcess.StandardInput.Flush()
GPGProcess.StandardInput.Close()

It still hangs at the passphrase prompt

-Phil
 
H

Herfried K. Wagner [MVP]

PAPutzback said:
No arguments -Error: cannot find file specified
System.Environment.CurrentDirectory = "c:\gnupg"
GPGProcess.StartInfo.WorkingDirectory = "c:\gnupg"
GPGProcess.StartInfo.FileName = "echo little boy blue| gpg"
GPGProcess.StartInfo.CreateNoWindow = True
GPGProcess.StartInfo.UseShellExecute = False
GPGProcess.Start()

No space between pipe and the exectuble = same error

Add .exe = same error

Add the full path "echo little boy blue| c:\gnupg\gpg.exe" = same error

Paste this into a cmd window

C:\gnupg>echo little boy blue| c:\gnupg\gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

I know the command is valid and this variation works also
C:\gnupg>echo little boy blue| gpg.exe
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

And also
C:\gnupg>echo little boy blue| gpg
gpg: no valid OpenPGP data found.
gpg: processing message failed: eof

Put the arguments on
C:\gnupg>echo little boy blue| gpg --passphrase-fd 0 -d
c:\gnupg\anstest.gpg
Reading passphrase from file descriptor 0

You need a passphrase to unlock the secret key for
user: "Indiana Prohealth <[email protected]>"
1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07 (main key ID FA28FB8B)

gpg: encrypted with 1024-bit ELG-E key, ID 778EBE0E, created 2004-12-07
"Indiana Prohealth <[email protected]>"
This is a test of the emergency broadcast system...

BEEEEEEEEEEEEEEEEEEEEEEEPPPPPPPPPPPPPPPPPP!!!!!

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

Testing 1,2,3...

And it all works.

Is there not a straight up way to fire off a command like you were in the
command window?

'ECHO' is actually a command of the command shell ("CMD.EXE"). So you will
have to run "CMD.EXE" with the rest as parameter (or take a look at the
sample I already referenced in a previous post).
 
P

PAPutzback

Herfried said:
'ECHO' is actually a command of the command shell ("CMD.EXE"). So you
will have to run "CMD.EXE" with the rest as parameter (or take a look at
the sample I already referenced in a previous post).
Thanks for the code. I am on my way out but I plugged the entire line
into the textbox and it worked. So I'll pull what I need out of it.

Thanks again,
Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top