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. Calling another program

Calling another program

Scheduled Pinned Locked Moved C / C++ / MFC
c++linuxquestion
12 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.
  • K Kash

    Hi, I am trying to call an external program which operates in a Dos Shell from my Property-Page based MFC project. It takes an input data file and outputs another data file. Any suggestions? kash

    J Offline
    J Offline
    jhwurmbach
    wrote on last edited by
    #2

    What exactly is your problem? Does ::ShellExecute() not work?


    My opinions may have changed, but not the fact that I am right.

    1 Reply Last reply
    0
    • K Kash

      Hi, I am trying to call an external program which operates in a Dos Shell from my Property-Page based MFC project. It takes an input data file and outputs another data file. Any suggestions? kash

      V Offline
      V Offline
      vikramlinux
      wrote on last edited by
      #3

      I think you may call _spawnl with arguments..or May goto for ShellExecute..what else you want ?

      K 1 Reply Last reply
      0
      • V vikramlinux

        I think you may call _spawnl with arguments..or May goto for ShellExecute..what else you want ?

        K Offline
        K Offline
        Kash
        wrote on last edited by
        #4

        Just tried ShellExecute, which consequently is a pretty cool function. I'm trying to run a program in a different directory to the one my MFC project is kept in. I tried this: ShellExecute(NULL,"open","d:\My Documents\Folder\ProgramA.exe",NULL,NULL,SW_SHOWNORMAL); but it doesn't like the different folder. kash

        J 1 Reply Last reply
        0
        • K Kash

          Just tried ShellExecute, which consequently is a pretty cool function. I'm trying to run a program in a different directory to the one my MFC project is kept in. I tried this: ShellExecute(NULL,"open","d:\My Documents\Folder\ProgramA.exe",NULL,NULL,SW_SHOWNORMAL); but it doesn't like the different folder. kash

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #5

          You maybe need to escape the backslashes in your string: ShellExecute(NULL,"open","d:\\MyDocuments\\Folder\\ProgramA.exe",NULL,NULL,SW_SHOWNORMAL);


          My opinions may have changed, but not the fact that I am right.

          K 1 Reply Last reply
          0
          • J jhwurmbach

            You maybe need to escape the backslashes in your string: ShellExecute(NULL,"open","d:\\MyDocuments\\Folder\\ProgramA.exe",NULL,NULL,SW_SHOWNORMAL);


            My opinions may have changed, but not the fact that I am right.

            K Offline
            K Offline
            Kash
            wrote on last edited by
            #6

            yep that works but now the dos console opens up but doesn't initialise my ProgramA.exe. It just displays an empty dos window and hangs up.

            J 1 Reply Last reply
            0
            • K Kash

              yep that works but now the dos console opens up but doesn't initialise my ProgramA.exe. It just displays an empty dos window and hangs up.

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #7

              Kash wrote: It just displays an empty dos window and hangs up. I just tested with ipconfig.exe. It opens for a fraction of a second and closes. Maybe it is in your ProgramA.exe?


              My opinions may have changed, but not the fact that I am right.

              K 1 Reply Last reply
              0
              • J jhwurmbach

                Kash wrote: It just displays an empty dos window and hangs up. I just tested with ipconfig.exe. It opens for a fraction of a second and closes. Maybe it is in your ProgramA.exe?


                My opinions may have changed, but not the fact that I am right.

                K Offline
                K Offline
                Kash
                wrote on last edited by
                #8

                ProgramA.exe is fine when it's run outside my MFC project. The dos prompt works as it should when i call it explicitly but am getting problems when i call a program. Also all windows programs are executing correctly. I need ProgramA to work and hold until I have operated on it then i want to exit ProgramA and return to the MFC project. Kash

                J 1 Reply Last reply
                0
                • K Kash

                  ProgramA.exe is fine when it's run outside my MFC project. The dos prompt works as it should when i call it explicitly but am getting problems when i call a program. Also all windows programs are executing correctly. I need ProgramA to work and hold until I have operated on it then i want to exit ProgramA and return to the MFC project. Kash

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #9

                  Kash wrote: I need ProgramA to work and hold until I have operated on it then i want to exit ProgramA and return to the MFC project. I do not understand this sentence. Do you want programA to start in a DosBox, perform its function and close the dosbox? This works on my computer. Or do you need the dos box to stay open, to show the output of ProgramA?


                  My opinions may have changed, but not the fact that I am right.

                  K 1 Reply Last reply
                  0
                  • J jhwurmbach

                    Kash wrote: I need ProgramA to work and hold until I have operated on it then i want to exit ProgramA and return to the MFC project. I do not understand this sentence. Do you want programA to start in a DosBox, perform its function and close the dosbox? This works on my computer. Or do you need the dos box to stay open, to show the output of ProgramA?


                    My opinions may have changed, but not the fact that I am right.

                    K Offline
                    K Offline
                    Kash
                    wrote on last edited by
                    #10

                    the latter, as ProgramA requires user inputs and once these have been obtained, it can then perform it's function and be exited by the user.

                    J 1 Reply Last reply
                    0
                    • K Kash

                      the latter, as ProgramA requires user inputs and once these have been obtained, it can then perform it's function and be exited by the user.

                      J Offline
                      J Offline
                      jhwurmbach
                      wrote on last edited by
                      #11

                      Kash wrote: ProgramA requires user inputs Oh. I see. From you first post ("It takes an input data file and outputs another data file.") on, I always thought of command line params. For a test, I tried "more.com", (which also wants input) with ShellExecuteEx():

                      CString s ("C:\\WINNT\\system32\\more.com");
                      SHELLEXECUTEINFO SEI = {0};
                      SEI.cbSize = sizeof(SEI);
                      SEI.lpVerb = "open";
                      SEI.lpFile = s;
                      SEI.nShow = SW_SHOWDEFAULT;

                      BOOL err = ::ShellExecuteEx( &SEI );
                      if (err!=TRUE)
                      {
                      }

                      and it seems to work. If this does not help, maybe calling a Batch-file that in turn calls your program may help?


                      My opinions may have changed, but not the fact that I am right.

                      K 1 Reply Last reply
                      0
                      • J jhwurmbach

                        Kash wrote: ProgramA requires user inputs Oh. I see. From you first post ("It takes an input data file and outputs another data file.") on, I always thought of command line params. For a test, I tried "more.com", (which also wants input) with ShellExecuteEx():

                        CString s ("C:\\WINNT\\system32\\more.com");
                        SHELLEXECUTEINFO SEI = {0};
                        SEI.cbSize = sizeof(SEI);
                        SEI.lpVerb = "open";
                        SEI.lpFile = s;
                        SEI.nShow = SW_SHOWDEFAULT;

                        BOOL err = ::ShellExecuteEx( &SEI );
                        if (err!=TRUE)
                        {
                        }

                        and it seems to work. If this does not help, maybe calling a Batch-file that in turn calls your program may help?


                        My opinions may have changed, but not the fact that I am right.

                        K Offline
                        K Offline
                        Kash
                        wrote on last edited by
                        #12

                        Thank you very much for your help. kash

                        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