running system commands??

This is a discussion on running system commands?? within the C++ Programming forums, part of the General Programming Boards category; is there a way i can do a system command (if thats wut u call it) in c++ something lke ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    25

    running system commands??

    is there a way i can do a system command (if thats wut u call it) in c++ something lke
    cout << "net send * messsage";
    and if so how would i do it without having to display it in the dos windows with the cout?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    It's in the FAQ. Option 1, i.e. the system command would likely do what you want.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    6
    Here's what I did. Take a look.
    Code:
    // MeGaBite1's Net Send App v0.1
    #include <iostream>
    #include <sstream>
    #include <string.h>
    using namespace std;
    
    int main(void)
    {
        int nummsg;
        int n = 0;
        std::stringstream stream;
        char ipaddr[20];
        char msg[200];
    	
        cout << "MeGaBiTe1's Net Send App v0.1\n";
        cout << "Enter Computer Name or IP:\n ";
        cin >> ipaddr;
        cout << "Enter Message:\n ";
        cin.getline (msg,200);
        cin.getline (msg,200);
        cout << "Enter Number of Messages to be Sent:\n ";
        cin >> nummsg;
    	
        stream << "net send " << ipaddr << ' ' << msg; 
        
        system ("PAUSE");
       
        while (n < nummsg) {
            std::system(stream.str().c_str());
            n++;
        } 
        
        system ("PAUSE");
        
    return 0;
    }
    Last edited by MeGaBiTe1; 08-30-2004 at 05:40 PM.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    25
    so which command is the system one cause you jst gave me a program and i cant exactly tell

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    It's the one that says, "system". Do you know C++?

  6. #6
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Quote Originally Posted by sean_mackrory
    It's the one that says, "system". Do you know C++?
    the answer is pretty obvious

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  7. #7
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    so which answer is the obvious one cause you jst gave me a sentence and i cant exactly tell

  8. #8
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    i belive the should be clue enough








    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Umm.... I'll google it....

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    25
    im not very good at c++ yet and how am i supposed to know that answer thats y i asked (sean), i didn't ask for a whole program either (even though it was small)
    Code:
        stream << "net send " << ipaddr << ' ' << msg; 
        
        system ("PAUSE");
       
        while (n < nummsg) {
            std::system(stream.str().c_str());
            n++;
        } 
        
        system ("PAUSE");
    if its the system command why is there a stream next to the commands then a
    system ("PAUSE") thing, i assume its stream but i have no idea wut the system ("{AUSE") is?

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    A forum is not a good medium for teaching the basics of object oriented programming. To send a command to the system, place the command in a C-style string and place either the string literal or a pointer to the first element of the array in parenthese next to the word system, and be sure to include cstdlib.

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    25
    i dont really get wut you mean, could you just answer my question cause i still dont know the syntax of it or wut some of the other stuff in the net send program was

  13. #13
    Registered User
    Join Date
    Jul 2004
    Posts
    25
    can anyone help me???

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >can anyone help me???
    From what I can tell, you're beyond help. system is a function, you give it a C-style string containing the system command you want processed as an argument. For example, if I wanted to use the DOS pause command I would do this:
    Code:
    #include <cstdlib>
    
    ...
    
    std::system ( "pause" );
    If I wanted to do a tracert for cprogramming.com I would do this:
    Code:
    std::system ( "tracert www.cprogramming.com" );
    If that's too much for you then you need to go back to the beginning and study functions. Otherwise you'll just end up being frustrated.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. system commands
    By darealnash in forum C++ Programming
    Replies: 8
    Last Post: 08-25-2004, 07:20 PM
  2. Invoking system commands... "A better way?"
    By The_Muffin_Man in forum C++ Programming
    Replies: 10
    Last Post: 06-10-2004, 04:57 AM
  3. Running external commands from within c code
    By Nova_Collision in forum C++ Programming
    Replies: 1
    Last Post: 03-16-2004, 12:23 PM
  4. Capturing system commands
    By manwhoonlyeats in forum C Programming
    Replies: 2
    Last Post: 12-07-2002, 06:38 PM
  5. system commands
    By mervin in forum C Programming
    Replies: 3
    Last Post: 02-03-2002, 08:01 AM

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