-2

Here is my code:

        string prova = @"\\10.20.9.1\fold\BCK_Capriata\";
        var process = new System.Diagnostics.Process();
        var startInfo = new System.Diagnostics.ProcessStartInfo
        {
            WorkingDirectory = prova,
            WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
            FileName = "cmd.exe",
            RedirectStandardInput = true,
            UseShellExecute = false 
        };
        startInfo.EnvironmentVariables["Path"] = @"C:\Program Files\7-Zip";
        process.StartInfo = startInfo;
        process.Start();
        process.StandardInput.WriteLine("7z t *.7z");
        process.WaitForExit();
        Console.ReadLine();

I get this error:

CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Window directory.

How can I solve this?

EDIT: I understand that I can't start a process in a UNC path and it's better to use directly 7za.exe But now my question is: How can I tell to 7za that I want to test zip in the UNC folder?

Pietro Ariano
  • 113
  • 1
  • 2
  • 12
  • 1
    Why are you starting `cmd` and forcing it to parse another command line rather than just starting `7z` directly? – Damien_The_Unbeliever Sep 01 '17 at 08:39
  • because I need to check 7z file in the \\10.20.9.1\fold\BCK_Capriata\ folder – Pietro Ariano Sep 01 '17 at 08:42
  • 1
    "UNC paths are not supported." - Period. Pass the path as 7z cmd parameter not as "WorkingDirectory" to the process. And as Damien sais: use 7z.exe, not cmd.exe – Fildor Sep 01 '17 at 08:44
  • 2
    Read my question again. I'm not asking why you're trying to set the working directory. I'm asking why you're running `cmd` rather than running `7z` directly? You seem to be jumping through a number of unnecessary hoops here by *inserting* cmd between your program and the program you *want* to run. – Damien_The_Unbeliever Sep 01 '17 at 08:44
  • See https://www.dotnetperls.com/7-zip – Fildor Sep 01 '17 at 08:48
  • Possible duplicate of [Unzip a file in c# using 7z.exe](https://stackoverflow.com/questions/16558363/unzip-a-file-in-c-sharp-using-7z-exe) – Fildor Sep 01 '17 at 08:48
  • I don't undestand how running directly 7zip I can specify the folder where i want test zip – Pietro Ariano Sep 04 '17 at 08:40

1 Answers1

0

Run 7z directly rather than trying to invoke it through cmd. As you can see cmd cannot start with UNC paths as the current working directory.

Maritim
  • 2,111
  • 4
  • 29
  • 59
  • I don't undestand how running directly 7zip I can specify the folder where i want test zip – Pietro Ariano Sep 04 '17 at 10:00
  • I'd look at https://stackoverflow.com/questions/16558363/unzip-a-file-in-c-sharp-using-7z-exe?noredirect=1&lq=1 if I were you – Maritim Sep 05 '17 at 05:43