Starting CLI application programmatically does not work depending on arguments

Posted by Daniel Beck on Stack Overflow See other posts from Stack Overflow or by Daniel Beck
Published on 2010-05-19T11:57:58Z Indexed on 2010/05/19 12:20 UTC
Read the original article Hit count: 402

Filed under:
|
|
|

I try to start plink.exe (PuTTY Link, the command line utility/version of PuTTY) from a C# application to establish an SSH reverse tunnel, but it does no longer work as soon as I pass the correct parameters.

What does that mean? The following works as expected: it opens a command line window, displays that I forgot to pass the password for the -pw argument quits, and shows the prompt. I know it got the arguments, since it specifically requests the one thing I did not provide.

Uri uri = omitted;
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd";
info.Arguments = "/k \"C:\\Program Files (x86)\\PuTTY\\plink.exe\" -R 3389:" + uri.Host + ":" + uri.Port + " -N -l username -pw"; // TODO pwd
Process p = Process.Start(info);

I tried the same think with calling plink.exe directly instead of cmd.exe /k, but the window closes immediately, which is unfortunate for bug-hunting.

BUT when I pass a password in the arguments, plink.exe displays the program help (showing available parameters) and quits:

Uri uri = omitted;
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd";
info.Arguments = "/k \"C:\\Program Files (x86)\\PuTTY\\plink.exe\" -R 3389:" + uri.Host + ":" + uri.Port + " -N -l username -pw secretpassword";
Process p = Process.Start(info);

No indication of missing parameters. Both the cmd /k and plink.exe variants do not work (the latter closes immediately, so no information regarding different behaviour).

When I launch the application from the Windows 7 Start Menu launcher with the identical parameters, it opens a cmd.exe window and establishes the connection as requested.

What's wrong? Is there a way plink.exe notices it's not running in a real shell? If yes, how can I circumvent it, like the Start Menu "prompt" does?

I hope this question is right on SO, since it, though specifically for a single application, revolves around launching it successfully programmatically.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET