C# 通过C执行cmd命令时卡住#

C# 通过C执行cmd命令时卡住#,c#,C#,我正在编写一个C#代码,它将调用我的windows cmd并对其执行命令,但我陷入了最后一条语句中,因为在执行“pscp”命令后,它会要求输入我已经拥有的“用户名密码”,但我不知道我的代码如何处理它 我的代码示例: const string cmdtext = @"/k cd\&pscp.exe&pscp C:\Users\user\Desktop\Backup\standalone-full.xml username@hostname:/apps/tempdir/express

我正在编写一个C#代码,它将调用我的windows cmd并对其执行命令,但我陷入了最后一条语句中,因为在执行“pscp”命令后,它会要求输入我已经拥有的“用户名密码”,但我不知道我的代码如何处理它

我的代码示例:

const string cmdtext = @"/k cd\&pscp.exe&pscp C:\Users\user\Desktop\Backup\standalone-full.xml username@hostname:/apps/tempdir/express/standalone-full.xml"; 
Process.Start(@"C:\Windows\system32\cmd.exe", cmdtext);                                        // after executing this command, it asks for the username's password
Console.ReadLine();

您可以改为尝试bitvise ssh客户端。您可以在该工具的命令行版本上输入密码


顺便说一句,您应该使用powershell而不是C来完成这些任务。

我通常这样称呼pscp:

pscp -l <username> -pw <password> <options> <source> <host>:<target>

这在没有提示的情况下可以工作,因为我知道您可以将用户名和密码作为参数传递给pscp,它不会以交互方式询问它们()您可以使用这个过载的进程。启动它:pscp-pw root C:\myfile.txtusername@192.168.0.1:/home/myfile.txt是否尝试使用重载
Process.Start(字符串文件名、字符串参数)
是否向流程提供参数?
pscp -l root -pw root C:\myfile.txt 192.168.0.1:/home/myfile.txt