這不是一個普遍的問題,而是一個特定於應用程序的問題。我碰巧正在做同樣的事情。我們可能不應該在這裏討論這個問題,但是請原諒我,我只是想幫忙。
關鍵的一點是,你需要輸入正確的論據,罐子
var processInfo = new ProcessStartInfo("java.exe", "-jar SentiStrengthCom.jar stdin sentidata data201109/ scale"){ ... }
下面是一個有效的解決方案:
// Start the java server, probably in a background thread
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
string directory = ...; // the directory of jar
var processInfo = new ProcessStartInfo("java.exe", "-jar SentiStrengthCom.jar stdin sentidata data201109/ scale")
{
// Initialize properties of "processInfo"
CreateNoWindow = true,
UseShellExecute = false,
WorkingDirectory = directory,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
};
JavaSentiStrength = new Process();
JavaSentiStrength.StartInfo = processInfo;
JavaSentiStrength.Start();
Console.WriteLine("SentiStrengthCom Java is running...");
JavaSentiStrength.WaitForExit();
int exitCode = 0;
if (JavaSentiStrength != null) exitCode = JavaSentiStrength.ExitCode;
Debug.WriteLine("Java SentiStrengthCom closed down! " + exitCode);
JavaSentiStrength.Close();
JavaSentiStrength = null;
}
// A button click
private void btnRequest_Click(object sender, EventArgs e)
{
JavaSentiStrength.StandardInput.WriteLine("love you ");
string s_out = JavaSentiStrength.StandardOutput.ReadLine();
Debug.WriteLine("SentiStrengthCom output: " + s_out);
}
輸出是
SentiStrengthCom輸出:3 -1 2
希望它有幫助!
而你的問題是....? –
你不清楚你在問什麼? – Tommassiov
也許你正在尋找'|'來將一個程序的輸出鏈接到另一個程序,比如'type my.txt |更多'...通常'cmd /?'將解決很多與之相關的問題。 –