简体   繁体   English

C#命令行执行命令属于另一个可执行文件

[英]C# command line execute commands belongs to another executable

Below is the code where I'm trying to run one command with argument. 下面是我尝试使用参数运行一个命令的代码。 (Call Tectia SFTP client profile & upload file) (调用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}");
         }

After the process started, it logins into the into the SFTP and stucked. 该过程开始后,它登录到SFTP中并被卡住。 It won't input the next command as it deemed as another program. 它不会输入下一个命令,因为它被视为另一个程序。

Would like to ask how does it execute the next command after login? 想问一下登录后如何执行下一个命令? I tried Calling CMD with && concatenating and it won't works too. 我尝试了通过&&串联调用CMD,但也无法正常工作。 We can only use SFTP via command line as client requested. 我们只能根据客户要求通过命令行使用SFTP。

  • Launch sftpg3 with the -B - option to read from standard input. 使用-B -选项启动sftpg3以从标准输入中读取。

  • Launch sftpg3 with the -B <filename> option to read from a batch file of commands. 使用-B <filename>选项启动sftpg3 ,以从命令批处理文件中读取。

More details of command line arguments is available in the documentation. 文档中提供了命令行参数的更多详细信息

Also, I don't think you want to write /c the second time around. 另外,我不希望您第二次写/c /c is just something passed to cmd.exe . /c只是传递给cmd.exe东西。 On that note, why are you calling cmd.exe instead of the binary directly? 关于这一点,为什么要直接调用cmd.exe而不是二进制文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM