I would like to ask a few questions:
•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?
•How do I display the results of the console? Should I use “console.writeline”?
The mactime.pl is from “The Sleuth Kit” windows.
The command works perfectly on the normal command prompt. The C# console program executes with errors of:
“Can’t open C:\temp\bin\testing.bodyfile -z UCT-8 >C:\temp\bin\testing2.txt at C:\temp\bin\mactime.pl line 282.”
and does not disply any results. There is no “testing2.txt” being generated after the program was executed.
The following are my codes:
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 Arguments:
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
-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)
Fix the arguments. On your code it currently looks like:
Notice the unmatched
"and there’s no space after>.Change that into:
Its now like: