繁体   English   中英

如何在C#Web应用程序中运行命令工具exe?

[英]How to run a command tool exe in C# web application?

我正在使用graphicmagic exe使用命令提示符执行命令。 我在我的应用程序根文件夹中添加了graphicmagic exe。 我想执行此exe并通过c#传递参数。 这个怎么做? 我尝试了以下代码:

方法:1

Process proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
         FileName = AppDomain.CurrentDomain.BaseDirectory + "\\gm1.3.5\\gm",
         Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 'D:\\Image\\FFv1\\dpx1\\1.dpx' 'D:\\Image\\FFv1\\tiff1\\1.tiff'",
         UseShellExecute = false,
         RedirectStandardOutput = true,
         CreateNoWindow = true
    }
}

方法:2

Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = @"D:\Executable\Projects\MMF\gm1.3.5\gm";
startInfo.Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 \"D:\\Image\\FFv1\\dpx1\\1.dpx\" \"D:\\Image\\FFv1\\tiff1\\1.tiff\"";
proc.StartInfo = startInfo;
proc.Start();

但是,两者都不起作用。 请提出一种执行exe文件并传递命令的方法。

这应该是特权问题。 尝试将您的应用程序池中的身份调整为LocalSystem。

这个工作正常:

using System.Diagnostics;

Process p = new Process();
p.StartInfo.FileName = @"D:\Executable\Projects\MMF\gm1.3.5\gm.exe";
p.StartInfo.Arguments = "convert -define dpx:colorspace=rgb -define tiff:bits-per-sample=16 \"C:\\Documents and Settings\\software\\Desktop\\DPX_Test\\3.dpx\" \"C:\\TEMP_21May2015103216\\3.tiff\"";
p.Start();                
p.WaitForExit();

暂无
暂无

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

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