Changeset 2203 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Oct 4, 2002, 3:25:17 PM (23 years ago)
Author:
cmv
Message:

cshell command.... cmv 04/10/02

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/piacmd.cc

    r1920 r2203  
    323323usage += "  > listcommands  # List of all known commands \n";
    324324usage += "  > exec filename # Execute commands from file \n";
    325 usage += "  > shell comand_string  # Execute shell command \n";
    326325usage += "  > help <command_name>  # <command_name> usage info \n";
    327326usage += "  > helpwindow           # Displays help window \n";
    328327usage += "  > timingon  timingoff traceon  traceoff \n";
    329328string grp = "Commands";
     329RegisterHelp(kw, usage, grp);
     330
     331kw = "shell execute";
     332usage  = "> shell  command_string  # Execute  shell command\n";
     333usage += "> cshell command_string  # Execute cshell command\n";
     334usage += "---Exemples:\n";
     335usage += "  > shell ls\n";
     336usage += "  > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n";
     337usage += "  > shell myfile.csh [arg1] [arg2] [...]\n";
     338usage += "    (where the first line of \"myfile.csh\" is \"#!/bin/csh\")\n";
    330339RegisterHelp(kw, usage, grp);
    331340
     
    983992  system(cmd.c_str());
    984993  }
     994else if (kw == "cshell") {
     995  if(tokens.size()<1) {cout<<"PIACmd::Interpret() Usage: cshell cmdline"<<endl; return(0);}
     996  string cmd="";
     997  for(int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
     998  CShellExecute(cmd);
     999  }
    9851000
    9861001//  Execution d'une commande enregistree
     
    11071122}
    11081123
     1124/* --Methode-- */
     1125int PIACmd::CShellExecute(string cmd)
     1126{
     1127 if(cmd.size()<=0) return -1;
     1128
     1129 NamedObjMgr omg;
     1130 string fname = omg.GetTmpDir(); fname += "cshell_exec_pia.csh";
     1131
     1132 string cmdrm = "rm -f " + fname;
     1133 system(cmdrm.c_str());
     1134
     1135 FILE *fip = fopen(fname.c_str(),"w");
     1136 if(fip==NULL)   {
     1137   cout << "PIACmd/CShellExecute_Error: fopen("<<fname<<") failed"<<endl;
     1138   return -2;
     1139 }
     1140 fprintf(fip,"#!/bin/csh\n\n");
     1141 fprintf(fip,"%s\n",cmd.c_str());
     1142 fprintf(fip,"\nexit 0\n");
     1143 fclose(fip);
     1144
     1145 cmd = "csh "; cmd += fname;
     1146 system(cmd.c_str());
     1147
     1148 system(cmdrm.c_str());
     1149
     1150 return 0;
     1151}
    11091152
    11101153static string* videstr = NULL;
  • trunk/SophyaPI/PIext/piacmd.h

    r1920 r2203  
    8282  virtual int           ExecuteCommand(string& keyw, vector<string>& args, string& toks);
    8383  virtual int           ExecFile(string& file, vector<string>& args);
    84 
     84  virtual int           CShellExecute(string cmd);
    8585  virtual string&       GetUsage(const string& kw);
    8686
Note: See TracChangeset for help on using the changeset viewer.