summaryrefslogtreecommitdiff
path: root/tools/bash-c.c
blob: 6b2844d5e5aff29b1de150d5005e4f5b90cdf41f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//////////////

using namespace std;
#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>              /* for perror() */
#include <stdlib.h>             /* for exit() */


string dirname(const string path){
  size_t where = path.rfind("/");
  if (where == string::npos) return ".";
  return path.substr(0, where);
}

int main(int argc, char** argv){
  int verbosity(0);
  
  char* nargv[1+argc];
  for (int ii = 1; ii <= argc; ii++){
    if (verbosity) {
      if (argv[ii] == 0) cout << "zero" << endl;
      else cout << "[" << argv[ii] << "]" << endl;
    }
    nargv[1+ii] = argv[ii];
  }
  nargv[1] = (char*)"-c";
  nargv[0] = (char*)"/home/jsd/bin/ECHO";
  nargv[0] = (char*)"/bin/bash";

  execv(*nargv, nargv);
  cerr << "bash-c: exec failed for '" << *nargv << "' : ";
  perror(0);
}