简体   繁体   English

将 arguments 从 C# 进程传递给 shell 脚本

[英]Passing arguments to a shell script from C# process

I am stuck with a problem from many days.很多天以来,我都遇到了一个问题。

I am connecting to a linux box and want to run some scripts and collect back the file generated.我正在连接到一个 linux 盒子,并且想要运行一些脚本并收集生成的文件。

Steps are 1) connect 2) run some scripts (which are interactive and need inputs at some point) 3) get the file generated as a result.步骤是 1) 连接 2) 运行一些脚本(它们是交互式的并且在某些时候需要输入) 3) 获取生成的文件作为结果。

1) I am connecting to linux box through plink.exe (commandline version of putty.exe) this step is successful. 1)我是通过plink.exe(putty.exe的命令行版本)连接到linux盒子这一步成功的。

2) I am able to run scripts but when the scripts run it expects some input, i am not able to figure out how to pass these inputs to the script. 2)我能够运行脚本,但是当脚本运行时它需要一些输入,我无法弄清楚如何将这些输入传递给脚本。 what happens is the program hangs as the scripts does not complete.发生的情况是程序挂起,因为脚本没有完成。

These inputs are fixed and vary between certain values, i can hard code these values into application / program.这些输入是固定的并且在某些值之间变化,我可以将这些值硬编码到应用程序/程序中。

Please help me in doing this.请帮助我这样做。 Thanks in advance -Akash在此先感谢-Akash

You can use this code您可以使用此代码

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "YourFile.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "";//Arguments should be here
using (Process exeProcess = Process.Start(startInfo))
{
    exeProcess.WaitForExit();
}

you can use exeProcess.StandardOutput.ReadToEnd();你可以使用exeProcess.StandardOutput.ReadToEnd(); to get the results得到结果

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

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