Thread: Opening a .html file from the console

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    73

    Opening a .html file from the console

    Hey everyone. My game's compiler is written in C++ in the console, and because of that, I can't do any graphics. But in the compiler, I need sort of a "Preview" mode, so I can generate a .html file that shows a preview of the map. Last time I tried this, it worked pretty well, except for one thing.

    When I opened the .html file from the console when other internet explorer windows were open, it said the file was not found. When I opened the .html file from the console when no other internet explorer windows were open, it worked just fine. Why is this happening?

    I'm using an ofstream in text mode, writing the HTML, and then using the system() function to open it.

    Thanks!

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    show me your system() line of code,
    i think i know what your problem is but i dont
    want to comment on it till i see the code.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    73
    Here's the code I used. I commented out all the outputting, so it's easier to read.

    Code:
    	ofstream Out;
    	Out.open( "MapDraft.html", ios::out );
    
    	// Writing html code to the file...
    
    	Out.close();
    
    	cout << "Now displaying Draft of Map ID " << MapID << '.' << endl;
    	cout << "Note: This might not work if any other Internet Explorer windows are open." << endl;
    
    	system( "MapDraft.html" );
    	remove( "MapDraft.html" );

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    system( "MapDraft.html" );
    Try
    Code:
    system("explorer MapDraft.html");
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    73
    Thanks! I'll try that when I get back to my compiler...

    ...but why would it matter? Doesn't it open .html files with explorer by default?

  6. #6
    Newbie Finneous's Avatar
    Join Date
    Aug 2005
    Location
    Finland
    Posts
    7
    My guess would be that the line remove("MapDraft.html") deletes the file before IE gains access.

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you are on windows, I'd recommend ShellExecute to open a html file

    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    If you have opera or firefox, then the system("explorer MapDraft.html"); wont open it in your default browser, ShellExecute will

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Verdagon
    ...but why would it matter? Doesn't it open .html files with explorer by default?
    depends on what the default browser is, AFAIK

    Quote Originally Posted by Finneous
    My guess would be that the line remove("MapDraft.html") deletes the file before IE gains access.
    I don't think system() returns until the process it calls returns...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Newbie Finneous's Avatar
    Join Date
    Aug 2005
    Location
    Finland
    Posts
    7
    I don't think system() returns until the process it calls returns...
    I just tried it, and it does. Use system("pause") after lauching the html file and you should do fine.

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Finneous
    I just tried it, and it does. Use system("pause") after lauching the html file and you should do fine.
    you seem to be right... but I would suggest not using system("pause"), and instead using cin.get();

    I would avoid using any system calls if at all possible. Fordy already gave you an alternative for windows.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM