0
#include <stdio.h>
#include<conio.h>
#include<string>
#include<iostream>
using namespace std; 
int main()
{
    string aa ,bb;
                  
    aa="mycomp"; //Comp name
    bb="User1"; //User name
         
     string r_parameter=" -l ";
     string r_parameter1=" -n ";
     string r_exe="ipconfig";
     aa.append(r_parameter);
     aa.append(bb);
     aa.append(r_parameter1);
     aa.append(r_exe);
     
     cout<<"\nHello\n";
     cout << aa << endl;
     system(" Rsh aa");
     getch();
  
}

problem is execution at here ---system(" Rsh aa");
but when run system (" Rsh mycomp -l User1-n ipconfig"); it works...
how to resolve this problem??

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Nick Evan
0

you're just executing "Rsh aa" ( system("Rsh aa"); ) which isn't a command.
To use a string with the system command, do something like:

int main()
{

    string command = "Rsh";

    string param1 = " -l";
    string param2 = " -n"; 
    //etc
    //etc
    string commandline = command + param1 + param2;
    cout << commandline << "\n";
    system(commandline.c_str());
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.