根据参数以编程方式启动 CLI 应用程序不起作用
我尝试从 C# 应用程序启动 plink.exe
(PuTTY Link,命令行实用程序/PuTTY 版本)来建立 SSH 反向隧道,但是一旦我传递了正确的参数。
这意味着什么?以下内容按预期工作:它打开一个命令行窗口,显示我忘记传递 -pw
参数的密码退出,并显示提示。我知道它有论据,因为它特别要求我没有提供的一件事。
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);
我尝试了同样的想法,直接调用 plink.exe
而不是 cmd.exe /k
,但窗口立即关闭,这对于寻找错误来说是不幸的。
但是当我在参数中传递密码时,plink.exe
显示程序帮助(显示可用参数)并退出:
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);
没有缺少参数的指示。 cmd /k
和 plink.exe
变体都不起作用(后者立即关闭,因此没有有关不同行为的信息)。
当我使用相同的参数从 Windows 7“开始”菜单启动器启动该应用程序时,它会打开一个 cmd.exe
窗口并根据请求建立连接。
怎么了?有没有办法让 plink.exe
注意到它没有在真正的 shell 中运行?如果是,我该如何规避它,就像开始菜单“提示”一样?
我希望这个问题是正确的,因为它虽然专门针对单个应用程序,但围绕着以编程方式成功启动它为中心。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,此网页 表明 Putty 对非交互式登录感到不安。如果建议的解决方法没有帮助,我建议您在 Putty 支持论坛或 Superuser.com 上询问相关问题。否则它与 Process 类或 C# 语言无关。
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.