Thread: Can someone help me plz

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    Angry Can someone help me plz

    Before I show the code let me explain what I'm trying to do and that I've been at it for the last 2 1/2 hours and it is seriously starting to get under my skin lol.

    I have a dos program that will load files through it. It's kind of like a viewing program. This program isn't much use without the supported file types. If this program encounters an error while loading a file through itself, it hault loading it and display a message, then go back to the dos prompt.

    What I'm trying to do is surpress EVERYTHING that this program spits out onto the dos / dos box screen. This I can do fine lol. I will load a file through that program, with the program I'm creating now. While this external program is busy loading the file through itself I am surpressing everything it disaplays ( >NUL ) until it finally does it's thing. While the external program is loading a file through it and an error occurs however, I want to display my own message (easy) since I surpressed the standard one that the external program will be putting out (which is what I want). So, my program will do the work for you. It will activate this external dos program (command line) and tell it to load whatever file through it. If it runs into an error it displays a message. If it does not error, it does nothing(cause the external program loaded that file with no problem).

    Code:
    int main()
    {
    	if ((system("pgm >NUL") == 0))
    	{
    	printf("there was an error.");
    	}
    	else
    	{
    	printf("there wasn't an error");
    	}
    	return 0;
    }
    The world is waiting. I must leave you now.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Soooo, what's the problem?

    -Prelude
    My best code is written with the delete key.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    lol

    It displays "There was an error" evev if it worked!

    dam I should search the boards for the last time I asked this ( long time ago ) and SOMEONE here helped me out, they gave me exactly what I was looking for....
    The world is waiting. I must leave you now.

  4. #4
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Posts
    77
    .....that sounded a bit rude.....

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    system() does not return the exit status of the program it ran - it might for some, but that's non-standard

    It might be better to use one of the spawn functions in P_WAIT mode, and check it's exit status, but again, check the manual

  6. #6
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    here

    My previous post (last year) about this topic.
    I remember I got the info in this post to work, but I don't know how . I already see one problem in that post...
    system("program_call >NUL");
    if(system("program_call >NUL") == 0)
    .....that'll run the program twice.

    I've gotten all of this to work before, man I did it over and over and over again (2,000 lines worth, and you yourself Salem commented on the length of code inside one single function). No matter how many different ways I stabbed, strangled, choked, and shot at that program (with the system command in dos) I could "catch" it's error, and re-direct it to my own user friendly message.

    Now, I'm lucky to do anything!........

    Code:
    int main()
    {
    	if(system("edit >NUL") == 0)  // test with dos's edit program
    	{
    	printf("there was an error");
    	}
    	else
    	{
    	printf("no errors occured");
    	}
    	return 0;
    }
    This, runs the dos edit program and takes you back to dos with, "there was an error". I had a way before, where, if the program executed successfully, it wouldn't display anything. It would only display messages if their was abnormal action during the -startup- of the program.

    It was also, very little code(the actual checking).
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM