根据参数以编程方式启动 CLI 应用程序不起作用

发布于 2024-09-02 02:58:55 字数 1290 浏览 11 评论 0原文

我尝试从 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 /kplink.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肩上的翅膀 2024-09-09 02:58:55

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文