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. system command

system command

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
19 Posts 3 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.
  • I IlanTal

    Thanks for the answer Nave. That is exactly what I tried. To my disappointment, it doesn't work for the system command. Apparently the system command is too old?

    N Offline
    N Offline
    Naveen
    wrote on last edited by
    #4

    Did you try the ShellExecute() function ShellExecute( NULL, _T("open"), _T("C:\\Program Files\\Internet Explorer\\iexplore.exe "), NULL, NULL, SW_SHOW );

    nave [OpenedFileFinder]

    I 1 Reply Last reply
    0
    • N Naveen

      Did you try the ShellExecute() function ShellExecute( NULL, _T("open"), _T("C:\\Program Files\\Internet Explorer\\iexplore.exe "), NULL, NULL, SW_SHOW );

      nave [OpenedFileFinder]

      I Offline
      I Offline
      IlanTal
      wrote on last edited by
      #5

      Thanks again Nave. No I didn't and that is exactly the answer I am looking for. I knew there was something which replaces system, but I couldn't remember what it was. I will try ShellExecute immediately. Ilan

      N 1 Reply Last reply
      0
      • I IlanTal

        Thanks again Nave. No I didn't and that is exactly the answer I am looking for. I knew there was something which replaces system, but I couldn't remember what it was. I will try ShellExecute immediately. Ilan

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #6

        By the time i tried the system command for path having space and it is working. Please check you specified the parameter as below char *pPath = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""; system( pPath );

        nave [OpenedFileFinder]

        I 1 Reply Last reply
        0
        • N Naveen

          By the time i tried the system command for path having space and it is working. Please check you specified the parameter as below char *pPath = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""; system( pPath );

          nave [OpenedFileFinder]

          I Offline
          I Offline
          IlanTal
          wrote on last edited by
          #7

          Really? Unbelievable! Maybe the problem is that I'm giving an input and an output filename as parameters? If I do it at a command prompt with quotes, all works perfectly OK. If I do it by using system - on exactly the same string, it does nothing. I tried even moving the quotes to the directory with spaces, but it made no difference. c:"a b c"\dcmdjpeg C:\ic2006\dicom\kressel\study1\ctseries\view0405.dcm c:"a b c"\jpegUncompress.dcm I made a directory "a b c" just for test purposes. In this case I forgot the backslash "c:\a b c", but that isn't the problem. Could you do me a favor and see if system works if you pass parameters? For me it works fine so long as I don't both spaces in the path and spaces to separate parameters. Thanks, Ilan

          N 1 Reply Last reply
          0
          • I IlanTal

            Really? Unbelievable! Maybe the problem is that I'm giving an input and an output filename as parameters? If I do it at a command prompt with quotes, all works perfectly OK. If I do it by using system - on exactly the same string, it does nothing. I tried even moving the quotes to the directory with spaces, but it made no difference. c:"a b c"\dcmdjpeg C:\ic2006\dicom\kressel\study1\ctseries\view0405.dcm c:"a b c"\jpegUncompress.dcm I made a directory "a b c" just for test purposes. In this case I forgot the backslash "c:\a b c", but that isn't the problem. Could you do me a favor and see if system works if you pass parameters? For me it works fine so long as I don't both spaces in the path and spaces to separate parameters. Thanks, Ilan

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #8

            Can you tell me which command are you trying to execute using the system?

            nave [OpenedFileFinder]

            I 1 Reply Last reply
            0
            • N Naveen

              Can you tell me which command are you trying to execute using the system?

              nave [OpenedFileFinder]

              I Offline
              I Offline
              IlanTal
              wrote on last edited by
              #9

              It is an exe file which I received to decompress JPEG Dicom files. I'm sure the problem exists for any command which has parameters on the command line. Again it worked just fine until I tried using a path which included "Program Files". Maybe I should try to run notepad with an input file and see if notepad opens the file. I'll try something like ""c:\a b c\notepad" myfile.txt" First I'll try c:\ilan\notepad myfile.txt, since that should work.

              N 1 Reply Last reply
              0
              • I IlanTal

                This has got to be an easy question, but I can't find a place to start. I want to give a command inside my code. The problem is when the path has a space in it like c:\Program Files\... I wanted to use system(buff) where buff = "c:\Program Files\myDir\myProg" This works fine for paths without spaces, but there is something to replace it for paths with spaces. I just can't remember what it is. Thanks, Ilan

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #10

                your problem is because the \ character is understood as the escapment character, so, to "output" a \, you must type '\\' :

                buff = "c:**\\Program Files\\myDir\\**myProg"

                BTW, prefer avoid using the ::system() CRT function because it is not totaly safe. use it ::Shellexecute() or ::CreateProcess() instead.


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                1 Reply Last reply
                0
                • I IlanTal

                  It is an exe file which I received to decompress JPEG Dicom files. I'm sure the problem exists for any command which has parameters on the command line. Again it worked just fine until I tried using a path which included "Program Files". Maybe I should try to run notepad with an input file and see if notepad opens the file. I'll try something like ""c:\a b c\notepad" myfile.txt" First I'll try c:\ilan\notepad myfile.txt, since that should work.

                  N Offline
                  N Offline
                  Naveen
                  wrote on last edited by
                  #11

                  IlanTal wrote:

                  I'll try something like ""c:\a b c\notepad" myfile.txt"

                  in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get abcd you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"

                  nave [OpenedFileFinder]

                  I 2 Replies Last reply
                  0
                  • N Naveen

                    IlanTal wrote:

                    I'll try something like ""c:\a b c\notepad" myfile.txt"

                    in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get abcd you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"

                    nave [OpenedFileFinder]

                    I Offline
                    I Offline
                    IlanTal
                    wrote on last edited by
                    #12

                    Nave, thanks for all your kind help. It has been very useful indeed! Apparently it is a combination of system together with that particular exe I'm using. The exe has to parse the command line to get the input and output files and it has a subtle bug. All my experiments of using notepad worked fine. (I copied notepad into a b c for test purposes.) On the other hand that exe fails using the system command. If I take the buffer which I pass to system and copy it into a command box, all works fine! I think it is time to use ShellExecute as you originally suggested. The experiments have been fun, but the system command with that exe doing parsing don't seem to work. Ilan

                    1 Reply Last reply
                    0
                    • N Naveen

                      IlanTal wrote:

                      I'll try something like ""c:\a b c\notepad" myfile.txt"

                      in this case you should specify like system( "notepad.exe \"C:\\a b c\\myfile.txt"" ); note that \ " are all special character, when you want to insert a quote(") in a string u have to place a \ infront of it. suppose you hard code "abcd" in the code and passed to the system, then the function will get abcd you have to specify like "\"abcd\"" for the system() for it to get a string like "abcd"

                      nave [OpenedFileFinder]

                      I Offline
                      I Offline
                      IlanTal
                      wrote on last edited by
                      #13

                      Nave, I just wanted to let you know what a joy the ShellExecute is. I used c:\a b c\ as the default directory and I separated out the command from the parameters. In system it was all one big mess and the exe file got confused. With ShellExecute everything works like a charm. Thanks again for your generous help, Ilan

                      N 1 Reply Last reply
                      0
                      • I IlanTal

                        Nave, I just wanted to let you know what a joy the ShellExecute is. I used c:\a b c\ as the default directory and I separated out the command from the parameters. In system it was all one big mess and the exe file got confused. With ShellExecute everything works like a charm. Thanks again for your generous help, Ilan

                        N Offline
                        N Offline
                        Naveen
                        wrote on last edited by
                        #14

                        IlanTal wrote:

                        Thanks again for your generous help,

                        You are welcome.:)

                        nave [OpenedFileFinder]

                        I 1 Reply Last reply
                        0
                        • N Naveen

                          IlanTal wrote:

                          Thanks again for your generous help,

                          You are welcome.:)

                          nave [OpenedFileFinder]

                          I Offline
                          I Offline
                          IlanTal
                          wrote on last edited by
                          #15

                          I've run into a new problem. ShellExecute launches the program and then returns. I need the results of the program so I need to know when the program is finished. It turns out that system() returns only after the program has finished. Is there any obvious way to know the program has finished? Thanks, Ilan

                          N 1 Reply Last reply
                          0
                          • I IlanTal

                            I've run into a new problem. ShellExecute launches the program and then returns. I need the results of the program so I need to know when the program is finished. It turns out that system() returns only after the program has finished. Is there any obvious way to know the program has finished? Thanks, Ilan

                            N Offline
                            N Offline
                            Naveen
                            wrote on last edited by
                            #16

                            in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.

                            nave [OpenedFileFinder]

                            I 2 Replies Last reply
                            0
                            • N Naveen

                              in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.

                              nave [OpenedFileFinder]

                              I Offline
                              I Offline
                              IlanTal
                              wrote on last edited by
                              #17

                              Once again, thanks for your help. When I ran things under the debugger, I looked at the directories, saw what files there were, saw how they were created, and I was happy that everything was working. When I let it go, I realized I still had a problem. Your help has been extremely useful. Ilan

                              1 Reply Last reply
                              0
                              • N Naveen

                                in that case use the ShellExecuteEx() function. in that function you will get the handle of the new process. so after calling the ShellExecuteEx() function wait for the handle using the WaitForSingleObject() function.

                                nave [OpenedFileFinder]

                                I Offline
                                I Offline
                                IlanTal
                                wrote on last edited by
                                #18

                                My application is up and running at full speed. Thanks again, Ilan

                                N 1 Reply Last reply
                                0
                                • I IlanTal

                                  My application is up and running at full speed. Thanks again, Ilan

                                  N Offline
                                  N Offline
                                  Naveen
                                  wrote on last edited by
                                  #19

                                  IlanTal wrote:

                                  My application is up and running at full speed.

                                  congrads :-D

                                  nave [OpenedFileFinder]

                                  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