C#命令行执行命令属于另一个可执行文件
C# command line execute commands belongs to another executable
下面是我尝试 运行 一个带有参数的命令的代码。 (调用 Tectia SFTP 客户端配置文件并上传文件)
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = $"/c sftpg3 {profile}";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
using (StreamWriter sw = cmd.StandardInput){
if (sw.BaseStream.CanWrite)
sw.WriteLine($"/c sput {filename} {output}");
}
进程启动后,它登录到 SFTP 并卡住。它不会输入下一个命令,因为它被认为是另一个程序。
请问登录后如何执行下一条命令?我尝试使用 && 连接调用 CMD,但它也不起作用。我们只能根据客户要求通过命令行使用 SFTP。
使用 -B -
选项启动 sftpg3
以从标准输入读取。
使用 -B <filename>
选项启动 sftpg3
以从批处理中读取
命令文件。
有关命令行参数的更多详细信息,请参阅 the documentation.
此外,我认为您不想第二次写 /c
。 /c
只是传递给 cmd.exe
的东西。关于这一点,你为什么要调用 cmd.exe
而不是直接调用二进制文件?
下面是我尝试 运行 一个带有参数的命令的代码。 (调用 Tectia SFTP 客户端配置文件并上传文件)
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = $"/c sftpg3 {profile}";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
using (StreamWriter sw = cmd.StandardInput){
if (sw.BaseStream.CanWrite)
sw.WriteLine($"/c sput {filename} {output}");
}
进程启动后,它登录到 SFTP 并卡住。它不会输入下一个命令,因为它被认为是另一个程序。
请问登录后如何执行下一条命令?我尝试使用 && 连接调用 CMD,但它也不起作用。我们只能根据客户要求通过命令行使用 SFTP。
使用
-B -
选项启动sftpg3
以从标准输入读取。使用
-B <filename>
选项启动sftpg3
以从批处理中读取 命令文件。
有关命令行参数的更多详细信息,请参阅 the documentation.
此外,我认为您不想第二次写 /c
。 /c
只是传递给 cmd.exe
的东西。关于这一点,你为什么要调用 cmd.exe
而不是直接调用二进制文件?