Thread: putting variables together in system

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    putting variables together in system

    I'm trying to get a net send function workin in console.. heres my source
    Code:
    int main()
    {
    	cout<<"Enter IP address>"; // ASKS for IP
    	char ip[16];
    	cin>>ip; //PUTS IP in the variable
    	cout<<"\nEnter a message>"; //ASKS for message
    	char message[225];
    	cin.ignore(1,'\n'); //Ignores the \n
    	cin.getline(message, sizeof (message)); //GEts the message
    	cout<<"\nSending.."; //Just tells it its sending
    	return 0;
    }
    I'm trying to use
    system("net send (inputed IP) (inputed MESSAGE)");
    but i dont know how to get the inputed IP or message into the system command.

    by the way, this is in console if you cant figure out
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Anything you put within the quotes for the system argument is taken as a literal, it wont work.

  3. #3
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    yes, i know that. I tried this:

    system("net send ", ip, message);

    but it says SYSTEM DOES NOT HAVE 3 ARGUEMENTS TO PASS or something close to it.

    is there anyway to make this possible?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    check into sprintf()
    Away.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You could just use store "Net send [ip] [message]" in a char array and use that as the argument for system()
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Thanks alot, sprintf works just fine
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>You could just use store "Net send [ip] [message]" in a char array
    Read confuted's post again. That's exactly what he said.

    And, for some strange reason, I feel like being nice today. Clicky
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i got booted but while i tried to get back i whipped this up, its the easiest solution imo:

    Code:
    //Steven Billington
    //Main.cpp
    //[email protected]
    
    #include <iostream>
    #include <stdlib>
    #include <conio>
    #include <fstream>
    
    using namespace std;
    
    int main ()
    {
        char ip[100];
        char message[250];
    
        ofstream file;
    
        cout<<"\nEnter IP: ";
        cin.getline(ip, 99);
        cout<<"Message: ";
        cin.getline(message, 249);
    
        //open (or create) batch file. 
        file.open("c:\\temp.bat", ios::out,0);
    
        cout << "Creating Batch file please wait...." << endl;
    
        //write the net send command and its arguments
        //to the batch to be executed
        file<<"net send " << ip << " " << message << " ";
        
        //close the batch file
        file.close();
        
        //execute batch file
        system("c:\\temp.bat");
    
        return(0);
    }

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Try this before you go makin batch files:

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <sstream>
    
    using namespace std;
    
    int main( int argc, char** argv ) {
    
    	string IP, Message;
    	ostringstream NetCmd;
    
    	cout <<"Enter IP: " <<flush;
    	cin >>IP;
    
    	cout <<"Enter message: " <<endl;
    
    	cin.ignore( 2, '\n' );
    	getline( cin, Message );
    
    	NetCmd <<"net send " <<IP <<" " <<Message;
    
    	system( NetCmd.str().c_str() );
    }
    I can't really test to see if the net command works because I'm runnin linux right now, but you get the general idea hopefully.

  10. #10
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Aight i got my program working;;

    it asks for an IP address, then a message, and # of messages. I attached the file.

    (i'm so mad i have closed networking i cant use it except for LAN computers hehehe)

    Anyways you cant do much bad with this program, because you need the IP of the person you want to do it to, and you both need open networking. so dont get mad at me for making this ><

    PS it was also a test to test out the system(""); function
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  11. #11
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    you can make it easier and have the program auto execute the command that tells who all connected pc's and ip's are, forget the cmd tho.

  12. #12
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    oo that would be real cool.. but i'm running on a LAN only networked internet, so i can only use net on my brother, sister, and mom+dad's computer
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  13. #13
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I believe its "net view" but not sure
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  14. #14
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    thats the one. it lists the names of those connected, the name of the pc. You use this rather than the IP. So say the program loads and shows the following:

    Bob
    Bill
    Jon

    Now you can just type Bob in IP/NAME:

    So make two functions, one for the batch to do that in the load of the prog, and the other we already have just needs to be placed in its own function.

  15. #15
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    Oh yea by the way, does the system function return any value if lets say the net send doesn't send?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  2. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  3. Why Can't C++ Be Used to Develop Operating System?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2005, 06:16 AM
  4. Putting variables in SYSTEM
    By mycro in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2003, 07:59 PM
  5. System Calls && Variables
    By Okiesmokie in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 09:10 PM