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 / C++ / MFC
  4. HowTo get ShellExecute to run a command file?

HowTo get ShellExecute to run a command file?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studioadobelinux
8 Posts 5 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.
  • R Offline
    R Offline
    Robert Palma Jr
    wrote on last edited by
    #1

    Visual Studio 6.0, C/C++ I would like to run a command (batch) file from within my app that, among other things, copies some files that are passed to it on startup. In the 4th parameter of ShellExecute() I have 2 parameters separated by a blank space. === the command file: copy.cmd @echo off REM the echo command is a dignostic. echo 1 >> log.txt copy %1 c:\dir1 copy %2 c:\dir2 === the Shell Execute() call ShellExecute(NULL, "open", "copy.cmd","C:\\file1.txt C:\\file2.txt", NULL, SW_SHOWNORMAL); When this runs I get a quick flash of the screen. I'm guessing that a command window is opening and immediately closing. The command file does not seem to run. I've tried various machinations like running cmd.exe in parameter 3, but still can't get my command file to execute. Any help would be very much appreciated :-) Robert

    V K R 3 Replies Last reply
    0
    • R Robert Palma Jr

      Visual Studio 6.0, C/C++ I would like to run a command (batch) file from within my app that, among other things, copies some files that are passed to it on startup. In the 4th parameter of ShellExecute() I have 2 parameters separated by a blank space. === the command file: copy.cmd @echo off REM the echo command is a dignostic. echo 1 >> log.txt copy %1 c:\dir1 copy %2 c:\dir2 === the Shell Execute() call ShellExecute(NULL, "open", "copy.cmd","C:\\file1.txt C:\\file2.txt", NULL, SW_SHOWNORMAL); When this runs I get a quick flash of the screen. I'm guessing that a command window is opening and immediately closing. The command file does not seem to run. I've tried various machinations like running cmd.exe in parameter 3, but still can't get my command file to execute. Any help would be very much appreciated :-) Robert

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Check out CreateProcess(). Kuphryn

      R 1 Reply Last reply
      0
      • R Robert Palma Jr

        Visual Studio 6.0, C/C++ I would like to run a command (batch) file from within my app that, among other things, copies some files that are passed to it on startup. In the 4th parameter of ShellExecute() I have 2 parameters separated by a blank space. === the command file: copy.cmd @echo off REM the echo command is a dignostic. echo 1 >> log.txt copy %1 c:\dir1 copy %2 c:\dir2 === the Shell Execute() call ShellExecute(NULL, "open", "copy.cmd","C:\\file1.txt C:\\file2.txt", NULL, SW_SHOWNORMAL); When this runs I get a quick flash of the screen. I'm guessing that a command window is opening and immediately closing. The command file does not seem to run. I've tried various machinations like running cmd.exe in parameter 3, but still can't get my command file to execute. Any help would be very much appreciated :-) Robert

        K Offline
        K Offline
        KeyL
        wrote on last edited by
        #3

        You should specify the fifth parameter. For example: I put copy.cmd, a.log, b.log all in my d:\\temp. ShellExecute(NULL, "open", "copy.cmd", "a.log b.log", "d:\\temp", SW_SHOWNORMAL); Ray

        R 1 Reply Last reply
        0
        • R Robert Palma Jr

          Visual Studio 6.0, C/C++ I would like to run a command (batch) file from within my app that, among other things, copies some files that are passed to it on startup. In the 4th parameter of ShellExecute() I have 2 parameters separated by a blank space. === the command file: copy.cmd @echo off REM the echo command is a dignostic. echo 1 >> log.txt copy %1 c:\dir1 copy %2 c:\dir2 === the Shell Execute() call ShellExecute(NULL, "open", "copy.cmd","C:\\file1.txt C:\\file2.txt", NULL, SW_SHOWNORMAL); When this runs I get a quick flash of the screen. I'm guessing that a command window is opening and immediately closing. The command file does not seem to run. I've tried various machinations like running cmd.exe in parameter 3, but still can't get my command file to execute. Any help would be very much appreciated :-) Robert

          R Offline
          R Offline
          Ritu Kwatra
          wrote on last edited by
          #4

          Hi Robert, You need not to specify fifth parameter. I have tested the following on my system: HINSTANCE hInst = ShellExecute(NULL,NULL,"c:\\test\\copy.cmd","c:\\aa.txt c:\\tt.log","",SW_HIDE); and this is working fine on my system. Hope it will help you :) Ritu Kwatra

          R P 2 Replies Last reply
          0
          • V valikac

            Check out CreateProcess(). Kuphryn

            R Offline
            R Offline
            Robert Palma Jr
            wrote on last edited by
            #5

            Thank-you Kuphryn for your help! :-)

            1 Reply Last reply
            0
            • K KeyL

              You should specify the fifth parameter. For example: I put copy.cmd, a.log, b.log all in my d:\\temp. ShellExecute(NULL, "open", "copy.cmd", "a.log b.log", "d:\\temp", SW_SHOWNORMAL); Ray

              R Offline
              R Offline
              Robert Palma Jr
              wrote on last edited by
              #6

              Thank-you for your help, Ray. Yup, I've been ignoring the 5th parameter! Got it working now. :-)

              1 Reply Last reply
              0
              • R Ritu Kwatra

                Hi Robert, You need not to specify fifth parameter. I have tested the following on my system: HINSTANCE hInst = ShellExecute(NULL,NULL,"c:\\test\\copy.cmd","c:\\aa.txt c:\\tt.log","",SW_HIDE); and this is working fine on my system. Hope it will help you :) Ritu Kwatra

                R Offline
                R Offline
                Robert Palma Jr
                wrote on last edited by
                #7

                Thank-you for your help, Ritu. I've been ignoring the 5th parameter. Got it working now. :-)

                1 Reply Last reply
                0
                • R Ritu Kwatra

                  Hi Robert, You need not to specify fifth parameter. I have tested the following on my system: HINSTANCE hInst = ShellExecute(NULL,NULL,"c:\\test\\copy.cmd","c:\\aa.txt c:\\tt.log","",SW_HIDE); and this is working fine on my system. Hope it will help you :) Ritu Kwatra

                  P Offline
                  P Offline
                  Parikshit979
                  wrote on last edited by
                  #8
                  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