-
October 21st, 2008, 04:06 PM
#1
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!!!
-
October 22nd, 2008, 02:30 AM
#2
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"
-
October 22nd, 2008, 07:23 AM
#3
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?
-
October 22nd, 2008, 07:26 AM
#4
Re: Working in DOS. How to Launch another App?
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?
-
October 22nd, 2008, 07:36 AM
#5
Re: Working in DOS. How to Launch another App?
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 \
-
October 22nd, 2008, 09:07 AM
#6
Re: Working in DOS. How to Launch another App?
-
October 22nd, 2008, 09:37 AM
#7
Re: Working in DOS. How to Launch another App?
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.
-
October 22nd, 2008, 09:38 AM
#8
Re: Working in DOS. How to Launch another App?
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!
-
October 22nd, 2008, 05:57 PM
#9
Re: Working in DOS. How to Launch another App?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|