system command

This is a discussion on system command within the C Programming forums, part of the General Programming Boards category; hi, Following code is not working.Help me #include<stdio.h> #include<dir.h> void main() { system("myprogram.exe"); } Please tell me that how system ...

  1. #1
    vk
    Guest

    system command

    hi,
    Following code is not working.Help me
    #include<stdio.h>
    #include<dir.h>
    void main()
    {
    system("myprogram.exe");
    }

    Please tell me that how system command command work.
    Donot use link to tutorial of this site.It is not working.
    thanks

  2. #2
    Im a Capricorn vsriharsha's Avatar
    Join Date
    Feb 2002
    Posts
    192

    Thumbs up

    If ur OS is Windows then forget abt it. It never worked for me either.

  3. #3
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    I'm not sure if you are getting a compile time or runtime error, but I believe system() is part of stdlib.h. Try including that.

    If that does not solve your problem, please give a description of the error you are receiving.
    Jason Deckard

  4. #4
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633

    Re: system command

    Originally posted by vk
    system("myprogram.exe");
    Also, your current working directory might not be what you think it is. Consider using the full path to 'myprogram.exe', instead of assuming it will be found.
    Jason Deckard

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Or have the executable file in the directory of the other program.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try omitting the .exe off of the end.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>Try omitting the .exe off of the end.

    That wont do it. How about Try; "Giving some useful information such as what isnt working... Some errors maybe? Some symptoms? Throw us a bone!"
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  8. #8
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    The problem is that you are just saying run this program when the current working directory is somewhere else.

    Do this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
       system("c:\\system\\program.exe");
       return0;
    }
    That should work

  9. #9
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    And don't put in stdio.h because you do not need it...

    !!!!!ANSI!!!!!!

    Code:
    #include <stdlib>
    using namespace std;   // or using std::system
    
    int main()
    {
        system ("cls");
        system ("pause");
        system ("ping http://www.yahoo.com");
        system ("yourfile.exe");
        system ("pause");
        system ("cls");
        return 0;
    }
    Blue

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Betazep
    And don't put in stdio.h because you do not need it...

    !!!!!ANSI!!!!!!

    Code:
    #include <stdlib>
    using namespace std;   // or using std::system
    
    int main()
    {
        system ("cls");
        system ("pause");
        system ("ping http://www.yahoo.com");
        system ("yourfile.exe");
        system ("pause");
        system ("cls");
        return 0;
    }
    Go back to the C++ board. We don't use name spaces or "<stdlib>" here.

    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    LOL...

    Sorry about that... followed it in from a link.

    Do you use system? I thought that was a C++ standard function?????
    Blue

  12. #12
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Blue

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Many functions that are standard to C are also in C++. Just like the syntax is the same. Basicly C++ is an extension of C, and as such, it has many similar functions and behaviour.

    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    OIC
    Blue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. system command not executing with format specifier
    By ridhamshah in forum C Programming
    Replies: 6
    Last Post: 11-08-2006, 05:58 AM
  2. Help on System Command
    By Smoki in forum C++ Programming
    Replies: 5
    Last Post: 12-14-2005, 06:47 PM
  3. Problem using system() command.
    By mmongoose in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2005, 09:44 PM
  4. System() command opens a dos-box
    By phil_drew in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2004, 07:43 AM
  5. IDEA: Customizeable command system
    By Inquirer in forum Contests Board
    Replies: 1
    Last Post: 10-02-2002, 11:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21