DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   trying to run a string as a command (http://www.daniweb.com/forums/thread181924.html)

eviocg Mar 16th, 2009 11:37 pm
trying to run a string as a command
 
The program psexec runs any command remotely on another computer. the syntax is "psexec \\RemoteComputer cmd.exe"
I want to run "start "www.website.com" on computers a19-(01-29)
any help would be appreciated


#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>


using namespace std;

int main(int argc, char *argv[])
{
        int compNum;
        compNum=0;
        std::string zero="0";
        std::string foo,s1,s,s2,s3,s6,s7,s8,s10;
        std::string command;
       
       
////////////////////////////////////////////////////////////////////////


        for (compNum; compNum < 10;compNum++)
              {

std::string compNum2;
std::stringstream out;
out << compNum;
compNum2 = out.str();

//*
                  s1="psexec ";
                  s2= "\\";
                  s3="a19-";
                  s6=" cmd.exe";
                  s7=" '";
                  s8= "start";
                  command = " www.google.com";
                  s10="'";
                  foo = s1 + s2 += s2;
                  foo += s3 += zero;
                  foo += compNum2+= s6 += s7 += s8 += command;
                  foo += s10;
                  cout << foo;
                  cout << "\n";
                  }
                 
///////////////////////////////////////////////////////////////////


for (compNum; compNum < 30;compNum++)
              {

std::string compNum2;
std::stringstream out;
out << compNum;
compNum2 = out.str();

                  s1="psexec ";
                  s2= "\\";
                  s3="a19-";
                  s6=" cmd.exe";
                  s7=" '";
                  s8= "start";
                  command = " www.google.com";
                  s10="'";
                  foo = s1 + s2 += s2;
                  foo += s3;
                  foo += compNum2+= s6 += s7 += s8 += command;
                  foo += s10;
                  cout << foo;
                  cout << "\n";
                  system(foo);
                 
                  }
             

    system("PAUSE");
    return EXIT_SUCCESS;
}

VernonDozier Mar 17th, 2009 1:07 am
Re: trying to run a string as a command
 
I get these values in the foo variable when I run the program. Is this what should be passed to the system command?

Quote:

psexec \\a19-00 cmd.exe 'start www.google.com'
psexec \\a19-01 cmd.exe 'start www.google.com'
psexec \\a19-02 cmd.exe 'start www.google.com'
psexec \\a19-03 cmd.exe 'start www.google.com'
psexec \\a19-04 cmd.exe 'start www.google.com'
psexec \\a19-05 cmd.exe 'start www.google.com'
psexec \\a19-06 cmd.exe 'start www.google.com'
psexec \\a19-07 cmd.exe 'start www.google.com'
psexec \\a19-08 cmd.exe 'start www.google.com'
psexec \\a19-09 cmd.exe 'start www.google.com'
psexec \\a19-10 cmd.exe 'start www.google.com'
psexec \\a19-11 cmd.exe 'start www.google.com'
psexec \\a19-12 cmd.exe 'start www.google.com'
psexec \\a19-13 cmd.exe 'start www.google.com'
psexec \\a19-14 cmd.exe 'start www.google.com'
psexec \\a19-15 cmd.exe 'start www.google.com'
psexec \\a19-16 cmd.exe 'start www.google.com'
psexec \\a19-17 cmd.exe 'start www.google.com'
psexec \\a19-18 cmd.exe 'start www.google.com'
psexec \\a19-19 cmd.exe 'start www.google.com'
psexec \\a19-20 cmd.exe 'start www.google.com'
psexec \\a19-21 cmd.exe 'start www.google.com'
psexec \\a19-22 cmd.exe 'start www.google.com'
psexec \\a19-23 cmd.exe 'start www.google.com'
psexec \\a19-24 cmd.exe 'start www.google.com'
psexec \\a19-25 cmd.exe 'start www.google.com'
psexec \\a19-26 cmd.exe 'start www.google.com'

eviocg Mar 17th, 2009 1:38 am
Re: trying to run a string as a command
 
yes... all of those should be sent to cmd

nucleon Mar 17th, 2009 1:50 am
Re: trying to run a string as a command
 
You need to use the
/c
option on cmd:
psexec \\a19-00 cmd /c 'start www.google.com'


All times are GMT -4. The time now is 10:41 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC