trying to run a string as a command

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 6
Reputation: eviocg is an unknown quantity at this point 
Solved Threads: 0
eviocg eviocg is offline Offline
Newbie Poster

trying to run a string as a command

 
0
  #1
Mar 16th, 2009
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


  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11. int compNum;
  12. compNum=0;
  13. std::string zero="0";
  14. std::string foo,s1,s,s2,s3,s6,s7,s8,s10;
  15. std::string command;
  16.  
  17.  
  18. ////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. for (compNum; compNum < 10;compNum++)
  22. {
  23.  
  24. std::string compNum2;
  25. std::stringstream out;
  26. out << compNum;
  27. compNum2 = out.str();
  28.  
  29. //*
  30. s1="psexec ";
  31. s2= "\\";
  32. s3="a19-";
  33. s6=" cmd.exe";
  34. s7=" '";
  35. s8= "start";
  36. command = " www.google.com";
  37. s10="'";
  38. foo = s1 + s2 += s2;
  39. foo += s3 += zero;
  40. foo += compNum2+= s6 += s7 += s8 += command;
  41. foo += s10;
  42. cout << foo;
  43. cout << "\n";
  44. }
  45.  
  46. ///////////////////////////////////////////////////////////////////
  47.  
  48.  
  49. for (compNum; compNum < 30;compNum++)
  50. {
  51.  
  52. std::string compNum2;
  53. std::stringstream out;
  54. out << compNum;
  55. compNum2 = out.str();
  56.  
  57. s1="psexec ";
  58. s2= "\\";
  59. s3="a19-";
  60. s6=" cmd.exe";
  61. s7=" '";
  62. s8= "start";
  63. command = " www.google.com";
  64. s10="'";
  65. foo = s1 + s2 += s2;
  66. foo += s3;
  67. foo += compNum2+= s6 += s7 += s8 += command;
  68. foo += s10;
  69. cout << foo;
  70. cout << "\n";
  71. system(foo);
  72.  
  73. }
  74.  
  75.  
  76. system("PAUSE");
  77. return EXIT_SUCCESS;
  78. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: trying to run a string as a command

 
0
  #2
Mar 17th, 2009
I get these values in the foo variable when I run the program. Is this what should be passed to the system command?

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'
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 6
Reputation: eviocg is an unknown quantity at this point 
Solved Threads: 0
eviocg eviocg is offline Offline
Newbie Poster

Re: trying to run a string as a command

 
0
  #3
Mar 17th, 2009
yes... all of those should be sent to cmd
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: trying to run a string as a command

 
0
  #4
Mar 17th, 2009
You need to use the /c option on cmd:
psexec \\a19-00 cmd /c 'start www.google.com'
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC