Search code examples
c#argumentsargument-passing

Having an issue with running an external programs arguments in C#


I have the following command which works fine in Perl

my $bugcmd = `"C:\\Program Files (x86)\\McAfee\\VirusScan Enterprise\\scan32.exe" 
    $source /all /archive /loguser /prompt /log $path$itemID.txt /autoexit`;

However in C# I cannot for the life of me get the damn thing to create a log file in C# it scans it just doesn't create a log, any help would be appreciated.

string log = txtSource.Text + itemID + ".txt";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Program Files (x86)\McAfee\VirusScan Enterprise\scan32.exe";
startInfo.Arguments = drive + " /all /archive /loguser /prompt /autoexit /log" + log;
Process.Start(startInfo);

The path and the itemID look fine in the debugger. C:\Temp\itemID.txt


Solution

  • Using string.Format might help expose where the problem is (you're missing a space after \log). I think this might help:

    startInfo.Arguments = 
        string.Format("{0} /all /archive /loguser /prompt /autoexit /log {1}", drive, log);
    

    Sometimes it's a good idea to ensure that the log path is surrounded by quotes as well, if you're reading it from a .config or some other place that you don't have control, since it may have spaces in it. This might also apply to drive?

    To handle that case:

    startInfo.Arguments = 
        string.Format("\"{0}\" /all /archive /loguser /prompt /autoexit /log \"{1}\"", 
            drive, log);