开发者

Starting CLI application programmatically does not work depending on arguments

开发者 https://www.devze.com 2022-12-30 16:03 出处:网络
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 para

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 cm开发者_如何学God /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.


Yes, this web page suggests that Putty gets edgy about non-interactive logons. If the suggested workaround doesn't help, I recommend you ask questions about it at a Putty support forum or Superuser.com. It's got otherwise nothing to do with the Process class or the C# language.

0

精彩评论

暂无评论...
验证码 换一张
取 消