簡體   English   中英

將 arguments 從 C# 進程傳遞給 shell 腳本

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

很多天以來,我都遇到了一個問題。

我正在連接到一個 linux 盒子,並且想要運行一些腳本並收集生成的文件。

步驟是 1) 連接 2) 運行一些腳本(它們是交互式的並且在某些時候需要輸入) 3) 獲取生成的文件作為結果。

1)我是通過plink.exe(putty.exe的命令行版本)連接到linux盒子這一步成功的。

2)我能夠運行腳本,但是當腳本運行時它需要一些輸入,我無法弄清楚如何將這些輸入傳遞給腳本。 發生的情況是程序掛起,因為腳本沒有完成。

這些輸入是固定的並且在某些值之間變化,我可以將這些值硬編碼到應用程序/程序中。

請幫助我這樣做。 在此先感謝-Akash

您可以使用此代碼

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();
}

你可以使用exeProcess.StandardOutput.ReadToEnd(); 得到結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM