?
Solved

Running external zip utility  - command line error

Posted on 2006-04-12
3
Medium Priority
?
2,373 Views
Last Modified: 2010-05-18
I’ve been attempting to launch a zip utility from C#.NET code.  Unfortunately, the 7-Zip utility that I’m using doesn’t like the command line string that I’m passing in.  Without getting into the switch syntax for this utility, I can tell you that the command line in the code below works when the utility is launched from the command prompt, so no problem there.

Here’s the sample code:

using System.Diagnostics;

private void btnZipMe_Click(object sender, System.EventArgs e)
{
    string strCmdLine = @"7z a -tzip c:\backups\schoolname.zip \a\*.doc";        
    ProcessStartInfo psi = new ProcessStartInfo();

    psi.FileName = @"C:\Program Files\7-Zip\7zG.exe";
    psi.Arguments = strCmdLine;
    Process p = Process.Start(psi);
}

When the last line of code above executes, the external utility pops up a message box stating “Incorrect command line” . Additionally, just as a test, I also set up everything under my C: drive to avoid escape characters even though the literal symbol should handle that – same error. Any ideas?

Thanks,
Tom
0
Comment
Question by:tmccallister
3 Comments
 
LVL 1

Expert Comment

by:ositear
ID: 16439081
watch out for the \ escaping \. I mean use \\ instead of \

bye
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16440113
Shot in the dark...

Try setting the Working directory and starting it this way:

        Process p = new Process();
        p.StartInfo.FileName = @"C:\Program Files\7-Zip\7zG.exe";
        p.StartInfo.Arguments = @"7z a -tzip c:\backups\schoolname.zip \a\*.doc";
        p.StartInfo.WorkingDirectory = @"C:\Program Files\7-Zip\";
        p.Start();
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 16443125
And another run at it...

  private void btnZipMe_Click(object sender, System.EventArgs e)
  {
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = @"C:\Program Files\7-Zip\7z.exe";
    psi.Arguments = @"a -tzip ""c:\backups\schoolname.zip"" ""c:\FULL_PATH\a\*.doc""";
    Process p = Process.Start(psi);
  }
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question