Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to run commandLine that uses cmd.exe in C#

how to run commandLine that uses cmd.exe in C#

Scheduled Pinned Locked Moved C#
csharpc++tutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    Hi I would like write the function that does the same behavior of following C++ code. I tried to use the Process but I am sure I'm using it in worng way. Would you please guid me to the correct way to run the simple cmdLine? This is the way I use the Process and it opens the winzip application and does nothing. //progName = "c:\program files\winzip\winzip.exe" System.Diagnostics.Process.Start(progName, cmdLine); CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); //where cmdLine = "unzip "c:\a.zip" "c:\extractedfiles" Thank you.

    G 1 Reply Last reply
    0
    • P pnpfriend

      Hi I would like write the function that does the same behavior of following C++ code. I tried to use the Process but I am sure I'm using it in worng way. Would you please guid me to the correct way to run the simple cmdLine? This is the way I use the Process and it opens the winzip application and does nothing. //progName = "c:\program files\winzip\winzip.exe" System.Diagnostics.Process.Start(progName, cmdLine); CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); //where cmdLine = "unzip "c:\a.zip" "c:\extractedfiles" Thank you.

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Specify arguments by setting Arguments property of ProcessStartInfo object and pass it to Process class object

      P 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        Specify arguments by setting Arguments property of ProcessStartInfo object and pass it to Process class object

        P Offline
        P Offline
        pnpfriend
        wrote on last edited by
        #3

        Thank you for your answer Giorgi. I tried this way but got error... pStartInfo.CreateNoWindow = true; pStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pStartInfo.UseShellExecute = false; //and also tried with Yes pStartInfo.Arguments = cmdLine; pStartInfo.FileName = progName; pStartInfo.RedirectStandardError = true; System.Diagnostics.Process.Start(pStartInfo);

        G 1 Reply Last reply
        0
        • P pnpfriend

          Thank you for your answer Giorgi. I tried this way but got error... pStartInfo.CreateNoWindow = true; pStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pStartInfo.UseShellExecute = false; //and also tried with Yes pStartInfo.Arguments = cmdLine; pStartInfo.FileName = progName; pStartInfo.RedirectStandardError = true; System.Diagnostics.Process.Start(pStartInfo);

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          What is the actual value of cmdline that you passed?

          P 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            What is the actual value of cmdline that you passed?

            P Offline
            P Offline
            pnpfriend
            wrote on last edited by
            #5

            The actual command line that I'm passing is: wzunzip -d -o "c:\sample.zip" "c:\outputfolder" in C++ I simple has to pass the string to system(cmdLine ) function, void ExtractZip(CStirng fileName,CString folder) { CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); }

            G 1 Reply Last reply
            0
            • P pnpfriend

              The actual command line that I'm passing is: wzunzip -d -o "c:\sample.zip" "c:\outputfolder" in C++ I simple has to pass the string to system(cmdLine ) function, void ExtractZip(CStirng fileName,CString folder) { CString cmdLine; cmdLine.Format("wzunzip -d -o \"%s\" \"%s\"",fileName,folder);// setting command line System(cmdLine); }

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #6

              Are all the arguments and parameters correct? What error are you getting? What happen if you run the program which you want to start from cmd with those arguments?

              P 1 Reply Last reply
              0
              • G Giorgi Dalakishvili

                Are all the arguments and parameters correct? What error are you getting? What happen if you run the program which you want to start from cmd with those arguments?

                P Offline
                P Offline
                pnpfriend
                wrote on last edited by
                #7

                You are right, Giorgi.. My argument isn't correct. I found my error and now is working great. Thanks for your advises and help. ^_^

                G 1 Reply Last reply
                0
                • P pnpfriend

                  You are right, Giorgi.. My argument isn't correct. I found my error and now is working great. Thanks for your advises and help. ^_^

                  G Offline
                  G Offline
                  Giorgi Dalakishvili
                  wrote on last edited by
                  #8

                  You are welcome, glad that I helped you :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups