【问题标题】:How to run a command tool exe in C# web application?如何在 C# Web 应用程序中运行命令工具 exe?
【发布时间】:2015-07-29 12:53:00
【问题描述】:

我正在使用graphicmagic exe 使用命令提示符执行命令。我在我的应用程序根文件夹中添加了 graphicsmagic 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文件和传递命令的方法。

【问题讨论】:

  • 它们在哪些方面不起作用? (请记住,Web 应用程序以有限的权限和访问权限运行。)
  • 其实我是用shell方法在vb.net中使用这个exe来转换图像的,它的转换。当我尝试使用 C# 进行转换时,它没有转换。
  • 是否抛出异常?你能从这个过程中得到任何输出吗?
  • 没有例外。但是图像没有在路径中转换。
  • 如何在c#中调用exe并传递参数?像 vb.net 中的 shell

标签: c# shell web-applications command-line-arguments exe


【解决方案1】:

应该是权限问题。 尝试将您的应用程序池中的标识调整为 LocalSystem。

【讨论】:

    【解决方案2】:

    这个工作正常:

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

    【讨论】:

      猜你喜欢
      • 2018-02-03
      • 2015-06-11
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多