Re: unix system command



On Oct 24, 12:15 pm, aki <akhileshrawat...@xxxxxxxxx> wrote:

I want to use system command in my code to run below commands
in system.

 1)mkdir -p /alcatel/var/share/AFTR/BSC;

  2)  mount -F lofs /alcatel/var/share/AFTR/BSC   /var/sftp/bscsftp/
BSC

  3)  echo "/alcatel/var/share/AFTR/BSC     -       /var/sftp/bscsftp/
BSC      lofs    -       yes     -" >> /etc/vfstab

How can i do this ...
i performed like this
long status1 =system( ("mkdir -p /var/sftp/bscsftp/BSC").c_str() ) ;

error is :
const char* is not a structure type.

how to do this..can sombody help ???

Well, you have a char const[], which converts implicitly to the
char const* required by system. You could always write
system( std::string( "mkdir -p /var/sftp/bscsftp/BSC").c_str() ) ;
but quite frankly, I don't see any point of it. Use std::string
and its member function c_str() when you have to build up the
command string; just use string literals directly.

Also third command need some special synatax i guess...any
idea..

Why? The system function normally invokes a shell with "-c"
your_string, so all of the usual shell operators are there.
I've executed pipelines in system, and I've used it to start
processes in background, as well as redirecting input and
output.

--
James Kanze (GABI Software) email:james.kanze@xxxxxxxxx
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
.



Relevant Pages

  • Re: dh, the daemon helper
    ... some type is a special case, while const ordinarily binds to the ... ie char const * is a pointer to a constant ... no point in returning memory to the malloc heap. ... 2004 is the UNIX standard. ...
    (comp.unix.programmer)
  • review of the "container library", part 1/?
    ... A few warnings were issued with gcc 4.4.5 and the options in the Makefile. ... or cast to ... definition of struct tagBinarySearchTreeNode has "char factor;" which is used ... where GetElement returns const void *. ...
    (comp.lang.c)
  • Re: HPGCC: exit() and return
    ... The switch statements ... static char const *string2basen{ ... Do not declare char const * string; as a const value (use just ... pointer since it is 'const', ...
    (comp.sys.hp48)
  • Re: Q about passing data as a const array
    ... The const on the len parameter is superfluous; ... exactly equivalent to "const char *data", ... void func(const struct mydata foo); ... Applying const to a pointer parameter can be quite useful, ...
    (comp.lang.c)
  • Re: dh, the daemon helper
    ... some type is a special case, while const ordinarily binds to the ... ie char const * is a pointer to a constant ... since this is the way UNIX(*) processes work. ...
    (comp.unix.programmer)