Help With system(); command

This is a discussion on Help With system(); command within the C++ Programming forums, part of the General Programming Boards category; I have tryed different ways to solve this problem, but this is what I need help on. lets say my ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    26

    Help With system(); command

    I have tryed different ways to solve this problem, but this is what I need help on.


    lets say my program has already asked for a hostname and message

    each are set with

    char hostname[50];
    char message[256];

    and each called and stored with the input with
    cin.getline ( hostname, 50, '\n' );
    and the same for message

    What I would now like to do is use the system(); command to run a NET SEND

    and in the command include
    (NET SEND hostname message) where hostname and message already have a value.

    how would I do this. I have tryed like system("NET SEND " hostname message); and different things like that but it just wont work. I hope you get what I mean, thanks ALot!

    EDIT: I am using Dev-C++
    Last edited by GUIPenguin; 02-03-2005 at 09:42 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,547
    Use strcpy and strcat to build up a string, then pass the completed result to system()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this.
    Code:
    #include <string>
    using namespace std;
    .
    .
    string hostname;
    string message;
    
    //and each called and stored with the input with
    getline ( cin, hostname );
    getline ( cin, message );
    
    string command = "NET SEND " + hostname + " " + message;
    system(command.c_str());

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    26
    Thanks Swoopy, works great!

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, 04:58 AM
  2. Help on System Command
    By Smoki in forum C++ Programming
    Replies: 5
    Last Post: 12-14-2005, 05:47 PM
  3. Problem using system() command.
    By mmongoose in forum C++ Programming
    Replies: 2
    Last Post: 08-20-2005, 08:44 PM
  4. System() command opens a dos-box
    By phil_drew in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2004, 06:43 AM
  5. IDEA: Customizeable command system
    By Inquirer in forum Contests Board
    Replies: 1
    Last Post: 10-02-2002, 10:17 PM

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