CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2008
    Posts
    15

    Working in DOS. How to Launch another App?

    Hi,

    I have a question... here's the scenario:


    I will boot into DOS from a floppy. On the floppy, i will run my executable (myapp.exe). from myapp.exe, I want to launch another excutable called lwhiz.exe. myapp.exe is already programmed except for launching lwhiz.exe. I need to find a way to open lwhiz.exe with C++.


    i saw this FAQ: http://www.codeguru.com/forum/showthread.php?t=302501


    but which method is best when using DOS? I've tried spawnl without luck, and I don't think system() will work since it needs an explicit path.


    Can anyone help me out please?


    Thanks!!!

  2. #2
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: Working in DOS. How to Launch another App?

    You may not know the absolute path but you must know the relative path. For example, if lwhiz.exe is right next to myapp.exe, then your relative path is simply "lwhiz.exe". If your directory structure is:
    \---MyApp
    | myapp.exe
    |
    \---LWHIZ
    lwhiz.exe

    Then the relative path will be ".\\LWHIZ\\lwhiz.exe"
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  3. #3
    Join Date
    May 2008
    Posts
    15

    Re: Working in DOS. How to Launch another App?

    thanks for the reply.


    i tried using the relative path, but system() returns with "Bad command or filename". any ideas why?

  4. #4
    Join Date
    Oct 2006
    Location
    Singapore
    Posts
    346

    Re: Working in DOS. How to Launch another App?

    Quote Originally Posted by njuneardave
    thanks for the reply.


    i tried using the relative path, but system() returns with "Bad command or filename". any ideas why?
    Well, that's obviously because the exe could not be found. Are you sure you set the path properly?
    Believe in your Dreams, Work for what you Believe in.
    My thoughts? Angelo's Stuff
    Some fun things I've done: RayWatch, QuickFeed, ACSVParser

    @ngelo

  5. #5
    Join Date
    Oct 2008
    Posts
    68

    Re: Working in DOS. How to Launch another App?

    Quote Originally Posted by njuneardave
    Hi,

    I have a question... here's the scenario:


    I will boot into DOS from a floppy. On the floppy, i will run my executable (myapp.exe). from myapp.exe, I want to launch another excutable called lwhiz.exe. myapp.exe is already programmed except for launching lwhiz.exe. I need to find a way to open lwhiz.exe with C++.


    i saw this FAQ: http://www.codeguru.com/forum/showthread.php?t=302501


    but which method is best when using DOS? I've tried spawnl without luck, and I don't think system() will work since it needs an explicit path.


    Can anyone help me out please?


    Thanks!!!
    if both exe's are in the same folder, use

    system("start lwhiz.exe");




    If myapp.exe is in the parent folder (such as D:\\folder1\\ and lwhiz.exe is in a subfolder (such as D:\\folder1\\folder2\\) then use

    system("start .\\folder2\\lwhiz.exe);

    However, if both are on the same drive, then use the environment variable %systemdrive%

    For example, use system("start %systemdrive%\\folder1\\folder2\lwhiz.exe);

    this works as long as both are on the same drive. %systemdrive% returns the drive letter this app is running from, so if it is running from D:\folder1\, then %systemdrive% is set to "D:\" Oh, and remember to use"\\" instead of "\" since C++ interprets \\ as \

  6. #6
    Join Date
    Apr 2005
    Posts
    107

    Re: Working in DOS. How to Launch another App?

    autoexec.bat

  7. #7
    Join Date
    May 2008
    Posts
    15

    Re: Working in DOS. How to Launch another App?

    Quote Originally Posted by shadowx360
    if both exe's are in the same folder, use

    system("start lwhiz.exe");




    If myapp.exe is in the parent folder (such as D:\\folder1\\ and lwhiz.exe is in a subfolder (such as D:\\folder1\\folder2\\) then use

    system("start .\\folder2\\lwhiz.exe);

    However, if both are on the same drive, then use the environment variable %systemdrive%

    For example, use system("start %systemdrive%\\folder1\\folder2\lwhiz.exe);

    this works as long as both are on the same drive. %systemdrive% returns the drive letter this app is running from, so if it is running from D:\folder1\, then %systemdrive% is set to "D:\" Oh, and remember to use"\\" instead of "\" since C++ interprets \\ as \

    i tried this... but i still get bad command or filename error. using both explicit and relative paths =/

    and, yes, the exe name is typed correctly.

  8. #8
    Join Date
    May 2008
    Posts
    15

    Re: Working in DOS. How to Launch another App?

    Quote Originally Posted by rdrast
    autoexec.bat
    actually, even though i wanted to do this in C++, this is a great solution. since my code isn't cooperating, an autoexec.bat file is an excellent alternative. thanks for the great suggestion!

  9. #9
    Join Date
    Oct 2008
    Posts
    68

    Re: Working in DOS. How to Launch another App?

    Quote Originally Posted by njuneardave
    actually, even though i wanted to do this in C++, this is a great solution. since my code isn't cooperating, an autoexec.bat file is an excellent alternative. thanks for the great suggestion!
    True, and if you want, you can make the autorun.bat using C++. Try this:

    system("echo start lwhiz.exe >> autoexec.bat");
    system("start autoexec.bat");

    echo and then >> means the things in between gets written to autoexec.bat. It's way more simple then fout and all of that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured