title: C# console programming how to run perl script in command prompt?
body: <p>I would like to ask a few questions:</p>
  
  <p>•How to execute the command "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" in a C# console program?</p>
  
  <p>•How do I display the results of the console? Should I use "console.writeline"?</p>
  
  <p>The mactime.pl is from "The Sleuth Kit" windows.</p>
  
  <p>The command works perfectly on the normal command prompt. The C# console program executes with errors of: </p>
  
  <p>"Can't open C:\temp\bin\testing.bodyfile -z UCT-8 >C:\temp\bin\testing2.txt at C:\temp\bin\mactime.pl line 282."</p>
  
  <p>and does not disply any results. There is no "testing2.txt" being generated after the program was executed.</p>
  
  <p>The following are my codes:</p>
  
  <pre><code>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 &gt;" + 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.
      }
    }
    }
    }
  </code></pre>
  
  <p>Mactime.pl Arguments:</p>
  
  <p>mactime [-b body_file] [-p password_file] [-g group_file] [-i day|hour idx_file]
   [-d] [-h] [-V] [-y] [-z TIME_ZONE] [DATE]
          -b: Specifies the body file location, else STDIN is used
          -d: Output timeline and index file in comma delimited format
          -h: Display a header with session information
          -i [day | hour] file: Specifies the index file with a summary of results</p>
  
  <pre><code>    -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)
  </code></pre>