无法运行使用C#code的.exe程序 [英] Unable to run .exe application using C# code

查看:224
本文介绍了无法运行使用C#code的.exe程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要从我的C#程序调用带两个参数​​(PracticeId,者ClaimID)

I have an exe that I need to call from my C# Program with two arguments (PracticeId, ClaimId)

例如: 假设我有一个应用程序 test.exe的,其功能是根据给定的两个参数进行索赔。

For example: Suppose I have an application test.exe, whose functionality is to make a claim according to the given two arguments.

在CMD我通常会给出以下命令:

On cmd I would normally give the following command as:

test.exe的1 2

和它工作正常,并执行转换的工作。

And it works fine and performs its job of conversion.

不过,我想用我的C#code执行同样的事情。 我使用下面的示例code:

But I want to execute the same thing using my c# code. I am using the following sample code:

Process compiler = new Process();
compiler.StartInfo.FileName = "test.exe" ;
compiler.StartInfo.Arguments = "1 2" ;
compiler.StartInfo.UseShellExecute = true;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();

当我尝试 test.exe的使用上述code调用,它未能履行提出索偿TXT文件的操作。

When I try to invoke test.exe using the above code, it fails to perform its operation of making a claim txt file.

在哪里,这是问题?问题是否线程与否,​​我不知道。

Where is the issue in this? Whether the problem is threading or not, I don't know.

有人能告诉我什么,我需要在上面code键更改?

Can someone please tell me what I need to change in the above code?

推荐答案

您提供的code失败,出现以下错误,当我运行它:

The code you've supplied fails with the following error when I run it:

System.InvalidOperationException

System.InvalidOperationException

Process对象必须有   UseShellExecute属性设置为false   为了重定向IO流。

The Process object must have the UseShellExecute property set to false in order to redirect IO streams.

下面code正确执行,并通过传递参数:

The following code executes correctly and passes the arguments through:

var compiler = new Process();
compiler.StartInfo.FileName = "test.exe";
compiler.StartInfo.Arguments = "1 2";
compiler.StartInfo.UseShellExecute = true;
compiler.StartInfo.RedirectStandardOutput = false;
compiler.Start();

这篇关于无法运行使用C#code的.exe程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆