【问题标题】:Run Console application by providing one argument using web application通过使用 Web 应用程序提供一个参数来运行控制台应用程序
【发布时间】:2016-01-06 15:56:46
【问题描述】:

我在桌面上有一个名为 DocToPDF.exe 的控制台应用程序。我需要在单击 Web 应用程序的按钮时运行它。我想出了如何运行该应用程序。问题是,控制台应用程序需要一个参数。我需要弄清楚传递参数的方式。要传递的参数是“3750”这是我的代码

   System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = "cmd";
    process.StartInfo.WorkingDirectory = @"C:\Users\itadmin\Desktop\DocToPDF\DocToPDF\DocToPDF\bin\Debug";

    process.StartInfo.Arguments= "/c \"" + "DocToPDF.exe" + "\"";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardInput = true;
    process.Start();

这是我的控制台应用程序,它使用 Console.Readline 接受参数

  Console.Write("Enter Merchant Acct # : ");
  string strApprId = Console.ReadLine();
  strApprId = strApprId.Trim();
  Console.WriteLine("Something awesome is being processed......... ");

【问题讨论】:

  • 你为什么从cmd开始,然后通过DocToPDF.exe?不能直接启动DocToPDF.exe吗?然后传递参数?
  • 在 .exe 后使用空格,然后传递参数。 process.StartInfo.Arguments= "/c \"" + "DocToPDF.exe" + "\"" + " 3750";
  • 我尝试直接传递DocToPDF.exe,但它不接受参数。

标签: c# asp.net console-application


【解决方案1】:

你可以使用

System.Diagnostics.Process pr=new System.Diagnostics.Process();
pr.StartInfo.Arguments = "Specify arguments here";             
pr.StartInfo.FileName="Specify.exe file complete path here";
pr.Start();

【讨论】:

  • 谢谢你工作得很好。有没有办法不显示控制台窗口并在后台运行它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 1970-01-01
  • 2014-01-24
相关资源
最近更新 更多