Sorry if this is an obvious one,

I have searched but cant finds any answers :)

Im trying to create the simplest little exe file that when clicked on runs a htm page in the same directory...

so im using...

int main(int argc, char *argv[])
{
    system("start iexplore.exe %0\..\the_index.htm");
    return EXIT_SUCCESS;
}

It works tickety boo if i run it on my computer, in a folder on the desktop say, but if i then put it onto a cd, which is the aim, then it throws up a

cannot find 'file:///D://the_index.htm' make sure the path or Internet address is correct

The paths are correct as far as i can tell...

any ideas peeps?

thanks

Mike

When I attempt to do that from a command prompt I get that same error because there is no such thing as "%0...". Where did you get the idea of that %0 from anyway?

Sorry,

the idea came from a microsoft kb thing...

do you have any suggestion how i might achieve it?

thanks for the reply :)

for the current directory, no path specification is required.

e.g. system(" start my_index.html"); should do.

What is %0 supposed to represent? If you put that in a batch file then it is the first command line argument to the batch file, for example c:>mybatch.bat d: <Enter key> If you want to do a similar thing in a C or C++, all command-line arguments are in the argc, and argv parameters to main()

#include <string>

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     command += "\\the_index.htm"       
     system(command.c_str());
     return 0;
}

if i try that it doesnt load in ie, which is why i was trying to basically autodetect the current directory,

if i try that the page that IE tries to load is

http://the_index.htm/

which fails.


Thanks for the reply though

What is %0 supposed to represent? If you put that in a batch file then it is the first command line argument to the batch file, for example c:>mybatch.bat d: <Enter key> If you want to do a similar thing in a C or C++, all command-line arguments are in the argc, and argv parameters to main()

#include <string>

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     command += "\\the_index.htm"       
     system(command.c_str());
     return 0;
}

thanks

That i thought represented the directory from which the exe was executed, im trying to find the article i found....

If i use what you suggest it looks for the file in the c:\ rather than the current folder it is in... any further ideas?

if i try that it doesnt load in ie, which is why i was trying to basically autodetect the current directory,

When the program runs from a CD or DVD drive, the current directory is the drive letter of that drive. On my computer it would be either e: or f: (I have both a CD and DVD drives). Is the *.html file also on the CD ? If yes, then your program can call _getcwd() to get the path to the current working directory. Just add that to the code I posted previously

#include <string>
#include <windows.h>

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     else 
     {
          char path[_MAX_PATH];
          if( getcwd(path, sizeof(path) == NULL)
         { 
                cout << "Error getting current directory\n";
                return 1;
          }
          command += path;
      } 
 
     command += "\\the_index.htm"       
     system(command.c_str());
     return 0;
}

thanks, yes it is on the cd too, sorry, should have said that!

im seeing an error here

if( getcwd(path, sizeof(path) == NULL)

It is missing a ) i think, but when i add one it still errors

14 C:\Dev-Cpp\main.cpp [Warning] NULL used in arithmetic
14 C:\Dev-Cpp\main.cpp `getcwd' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)

ps this is the link to what i was trying to use...
http://helpdesk.kixtart.org/KixManual/RunningKiXtartFromABatchFile.asp

you have to include <direct.h>

yes, a ) is missing if( getcwd(path, sizeof(path)) == NULL)

>>ps this is the link to what i was trying to use...
It appears that the author of that argicle uses %0 to substitute the drive letter found in argv[0], but that may or may not work because the contents of argv[0] is compiler dependent. So it looks like the code I gave you to use getcwd() is a good substitute.

thanks,


again, this works when i have the file local, but if i burn them both to cd, ie the exe and the htm file, it fails with the following message again:

cannot find 'file:///D://the_index.htm' make sure the path or Internet address is correct

Any ideas why this might happen, im starting to go bald through hair pulling lol

what about
system ( "explorer.exe http:\\");

thanks Prabaker, can you expand on what you mean?

One point to note is that when that error pops up, and i click ok, then IE opens... if that makes a difference

ok, i think the error could be this.....

The error states:

file:///D://the_index.htm

when it should be

file:///D:/the_index.htm

notice the single /

No that's not it. I wanted to say more. But my mom called me for supper and I had to go, Now I am back. perhaps try this
file:////D://the_index.htm

I am not sure though

no that isnt a valid path,

i have tried substituting the iexplore.exe for explorer and it still fails,

I think the issue might be the address of the file that ie is looking for... but i dontknow how i would change it

To open a file in my drive I do something like this. It works for me though I cant say why it works
system ( "explorer E:\\Downloads\\serial.txt" ) ;
system ( "explorer E:\\Downloads\\SETUP.exe" ) ;

This worked perfectly for me:
Output of the program in the command window when run directly from the DVD drive.

start iexplore.exe F:\dvlp\the_index.html

here is the exact code

#include <string>
#include <iostream>
#include <windows.h>
#include <direct.h>
using namespace std;
#pragma warning(disable: 4996)

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     else 
     {
          char path[_MAX_PATH];
          if( getcwd(path, sizeof(path)) == NULL)
         { 
                cout << "Error getting current directory\n";
                return 1;
          }
          command += path;
      } 
 
     command += "\\the_index.html";
     cout << command << "\n";
     system(command.c_str());
     cin.get();
     return 0;
}
commented: Thanks, I Learned the fn getcwd() +1

aaargh,

this is wierd,

with your code as it is now

i get this error still....

http://www.organiclinker.com/doh.gif

does it matter how i compile it?

could you send me an exe so i can try it here please?

Perhaps.... I guess......... May be....... I have an error in my compiler. cause the code works perfectly to me:)

What did you give as the command line argument?

D:\boots_index.html

I compiled it and ran it as an exe file :(

sorry this is not my area,

I compiled it and ran it as an exe file :(

sorry this is not my area,

Say your .html file's full path is: "d:\folder\file.html", then the following command should do

// open the .html in default browser
system("start file://d:/folder/file.html");

I guess AD's command line approach is new to you.

If that is the case then I suppose you could do the following.
1) Learn to use Command line arguments
2) use system ( "explorer D:\\boot_index.html" ) ; The problem with this is that the address is absolute and therefore fixed.
3) Use AD's code without command line arguments. Its ain't that difficult

This worked perfectly for me:
Output of the program in the command window when run directly from the DVD drive.

start iexplore.exe F:\dvlp\the_index.html

here is the exact code

#include <string>
#include <iostream>
#include <windows.h>
#include <direct.h>
using namespace std;
#pragma warning(disable: 4996)

int main( int argc, char* argv[])
{
     std::string command = "start iexplore.exe ";
     if( argc == 2)
         command = argv[1];
     else 
     {
          char path[_MAX_PATH];
          if( getcwd(path, sizeof(path)) == NULL)
         { 
                cout << "Error getting current directory\n";
                return 1;
          }
          command += path;
      } 
 
     command += "\\the_index.html";
     cout << command << "\n";
     system(command.c_str());
     cin.get();
     return 0;
}

when you said this works, did you compile it and run it as an exe?

does it work then when you have the 2 files on the cd?

any ideas why mine might not im using bloodhsed dev-C++ - is there something else i can try?

I did use the same compiler. And it DOES WORK. Well, here is a program which does not use command line arguments.

#include <string>
#include <iostream>
#include <windows.h>
#include <direct.h>
using namespace std;
#pragma warning(disable: 4996)

int main( )
{
     std::string command = "start iexplore.exe ";
     char path[_MAX_PATH];
     cout << "Enter the Path of the file(say D:\boot_index.html): " ;
     cin >> path ;
     command+=path ;
     cout << command << "\n";
     cin.get();
     system(command.c_str());
     cin.get();
     return 0;
}

when you said this works, did you compile it and run it as an exe?

does it work then when you have the 2 files on the cd?

any ideas why mine might not im using bloodhsed dev-C++ - is there something else i can try?

When I run the program on the CD I didn't give it any command-line arguments. I just used Windows Explorer and double-clicked on the exe file. The compiler I used is VC++ 2008 Express, but for that tiny program there should be no difference because it doesn't use any compiler-specific stuff, just straight c++ and win32 api functions.

When I run the program on the CD I didn't give it any command-line arguments. I just used Windows Explorer and double-clicked on the exe file. The compiler I used is VC++ 2008 Express, but for that tiny program there should be no difference because it doesn't use any compiler-specific stuff, just straight c++ and win32 api functions.

If that is the case then the program uses the current working directory, which is not D:
Am I right ?

If that is the case then the program uses the current working directory, which is not D:
Am I right ?

You are right -- as I said a couple times before _getcwd() gets the current working directory, which is the drive letter of the CD or DVD drive when run from CD/DVD. And you can see that in the output that I posted --

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.