0

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

5
Contributors
31
Replies
32
Views
9 Years
Discussion Span
Last Post by mikesharp
0

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?

0

Sorry,

the idea came from a microsoft kb thing...

do you have any suggestion how i might achieve it?

thanks for the reply :)

0

for the current directory, no path specification is required.

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

0

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;
}
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

0

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?

0

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;
}
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

0

>>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.

0

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

0

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

0

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 /

0

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

0

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

0

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" ) ;

0

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;
}
Votes + Comments
Thanks, I Learned the fn getcwd()
0

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

0

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

sorry this is not my area,

0

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");
0

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

0

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?

0

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;
}
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.

0

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 ?

0

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 --

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.