0

Absolutely no C# experience here but been asked to edit a Windows Form Application and got a little stuck!

Upon clicking a button on the form the following coding runs:

private void RunHPPreSort_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("cmd.exe", @"/k C:\Program Files\Hewlett-Packard\HP Exstream\HP Exstream 8.0.310\Engine.exe");            
}

This works fine but I need to add in an arguments to allow Engine.exe to grab settings for a control file. I have tried changing the code to:

private void RunHPPreSort_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("cmd.exe", @"/k C:\Program Files\Hewlett-Packard\HP Exstream\HP Exstream 8.0.310\Engine.exe -CONTROLFILE=C:\Users\adam.pope\Desktop\Accenture\Control Files\Accenture Control File Step One.opt");            
}

I did this because running C:\Program Files\Hewlett-Packard\HP Exstream\HP Exstream 8.0.310\Engine.exe -CONTROLFILE=C:\Users\adam.pope\Desktop\Accenture\Control Files\Accenture Control File Step One.opt directly from the Command Line works perfectly. However when I use it through the Windows Form Application I get the following error in the on the Command Line:

'C:\Program' is not recognized as an internal or external command, operable program or batch files.

It seems that adding the "-" in before the arguments is causing the problem but this is the only way in which Engine.exe will accept arguments.

Is there a solution to this? Sorry if it is blindingly obvious but I have no idea what I'm doing in the C# world!

4

1 に答える 1

0

引用符で囲まれていないスペースがあるとcmdが実行されないため、引用符なしで以前にどのように機能していたかはわかりません。

代わりにこれを使用してみてください

System.Diagnostics.Process.Start("cmd.exe", "/k \"C:\\Program Files\\Hewlett-Packard\\HP Exstream\\HP Exstream 8.0.310\\Engine.exe\" -CONTROLFILE=C:\\Users\\adam.pope\\Desktop\\Accenture\\Control Files\\Accenture Control File Step One.opt");

パラメーターも引用符で囲む必要がある場合がありますが、それは、呼び出しているプログラムがスペースを含む引数をどのように処理するかによって異なります。

于 2013-01-29T15:28:19.017 に答える