简体   繁体   中英

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)

        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. 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. We can only use SFTP via command line as client requested.

  • Launch sftpg3 with the -B - option to read from standard input.

  • Launch sftpg3 with the -B <filename> option to read from a batch file of commands.

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 is just something passed to cmd.exe . On that note, why are you calling cmd.exe instead of the binary directly?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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