首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#控制台编程如何在命令提示符下运行perl脚本?

C#控制台编程如何在命令提示符下运行perl脚本?
EN

Stack Overflow用户
提问于 2010-11-15 15:09:21
回答 1查看 2.6K关注 0票数 0

我想问几个问题:

·如何在C#控制台程序中执行命令"C:\strawberry\perl\bin\perl.exe C:\temp\bin\mactime.pl -b C:\temp\bin\testing.bodyfile -z UCT-8 > C:\temp\bin\testing2.txt“?

·如何展示控制台的结果?我应该使用"console.writeline“吗?

mactime.pl来自“侦探工具包”窗口。

该命令在正常的命令提示符下工作得很好。C#控制台程序执行时出现以下错误:

“无法在C:\temp\bin\mactime.pl第282行打开C:\temp\bin\testing.bodyfile -z UCT-8 >C:\temp\bin\testing2.txt。”

并且不显示任何结果。程序执行后没有生成"testing2.txt“。

以下是我的代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics;

namespace ConsoleApplication1
{
class Program
{
   static void Main(string[] args)
   {
       LaunchCommandLineApp(); 
   }   

   static void LaunchCommandLineApp()
{
    // For the example
    const string ex1 = "C:\\temp\\bin\\mactime.pl";
    const string ex2 = "C:\\temp\\bin\\testing.bodyfile";
    const string ex3 = "C:\\temp\\bin\\testing2.txt";

    // Use ProcessStartInfo class
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "C:\\strawberry\\perl\\bin\\perl.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "\"" + ex1 + "\" -b " + ex2 + "\" -z UCT-8 >" + ex3;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using statement will close.
        using (Process exeProcess  = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
    catch
    {
        // Log error.
    }
  }
  }
  }

Mactime.pl参数:

mactime -b body_file -g group_file -d -V -z TIME_ZONE -b:指定正文文件位置,否则使用STDIN -d:以逗号分隔格式输出时间轴和索引文件-h:显示包含会话信息的标头-i day | hour file:指定包含结果摘要的索引文件

代码语言:javascript
复制
    -g: Specifies the group file location, else GIDs are used
    -p: Specifies the password file location, else UIDs are used
    -V: Prints the version to STDOUT
    -y: Dates have year first (yyyy/mm/dd) instead of (mm/dd/yyyy)
    -m: Dates have month as number instead of word (can be used with -y)
    -z: Specify the timezone the data came from (in the local system format)

    [DATE]: starting date (yyyy-mm-dd) or range (yyyy-mm-dd..yyyy-mm-dd)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-15 15:23:10

修复参数。在你的代码中,目前看起来是这样的:

"C:\temp\bin\mactime.pl“-b C:\temp\bin\testing.bodyfile”-z UCT-8 >C:\temp\bin\testing2.txt

注意不匹配的">后面没有空格。将其更改为:

代码语言:javascript
复制
startInfo.Arguments = "\"" + ex1 + "\" -b \"" + ex2 + "\" -z UCT-8 > \"" + ex3 + "\"";

它现在是这样的:

"C:\temp\bin\mactime.pl“-b "C:\temp\bin\testing.bodyfile”-z UCT-8 > "C:\temp\bin\testing2.txt"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4182158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档