I have written a code in which i want to open a HTM file when i select a particular option…
To achieve this i have created a batch file and opened it using system() as shown in code..
This is my code:
code:
#include <iostream.h>
#include <stdlib.h>
#include <dos.h>
#include <process.h>
void main()
{
cout<<"Hello World";
delay(3000);
system("a.bat");
delay(1000);
}
a.bat code:
start iexplore.exe c:\Turbo\TC\BIN\Hello.htm
When i just use this line in command line it executes but when i want to execute it using c++ code i get a bad filename or command error…
Please tell me if i am going wrong somewhere here.. or what can i do.
Please help..
Thank You..:)
Since most of your code isn’t particularly portable anyway, the right way is almost certainly to use
ShellExecuteto “execute” the HTML file directly. I, for one, would have to be pretty desperate before I’d put up with a program using IE to open HTML files.ShellExecuteis Windows-specific, but your code isn’t particularly portable right now. I suppose Unix (or similar) systems wouldn’t actually stop you from naming a shell scriptwhatever.bat, but it’s certainly uncommon. You certainly shouldn’t expectiexplore.exeto be available on most though (nor for executables in general to have a ‘.exe’ extension).