OpendTect  6.6
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
OS::MachineCommand Class Reference

Encapsulates an actual command to execute + the machine to run it on. More...

Public Member Functions

 MachineCommand (const char *prognm, bool isolated)
 
 MachineCommand (const char *prognm, const BufferStringSet &arguments)
 
 MachineCommand (const char *prognm, const char *arg1, const char *arg2=0, const char *arg3=0, const char *arg4=0, const char *arg5=0)
 
 MachineCommand (const char *prognm=nullptr)
 
 MachineCommand (const MachineCommand &, bool isolated)
 
MachineCommandaddArg (const char *)
 
template<class T >
MachineCommandaddArg (const T &t)
 
MachineCommandaddArgs (const BufferStringSet &)
 
MachineCommandaddFileRedirect (const char *fnm, int stdcode=0, bool append=false)
 
MachineCommandaddFlag (const char *flg, KeyStyle ks=NewStyle)
 
MachineCommandaddKeyedArg (const char *ky, const char *valstr, KeyStyle ks=NewStyle)
 
template<class T >
MachineCommandaddKeyedArg (const char *ky, const T &t, KeyStyle ks=NewStyle)
 
MachineCommandaddPipe ()
 
const BufferStringSetargs () const
 
const char * command () const
 
bool execute (BufferString &output_stdout, BufferString *output_stderr=nullptr, const char *workdir=nullptr)
 run &, wait until finished, catch output More...
 
bool execute (const CommandExecPars &)
 
bool execute (LaunchType lt=Wait4Finish, const char *workdir=nullptr)
 
const char * getSingleStringRep () const
 
BufferString getSingleStringRep (bool noremote=false) const
 
bool hasHostName () const
 
bool hostIsWindows () const
 
const char * hostName () const
 
bool isBad () const
 
const char * program () const
 
const char * remExec () const
 
BufferString runAndCollectOutput (BufferString *errmsg=nullptr)
 for quick get-me-the-output-of-this-command More...
 
void setCommand (const char *)
 
bool setFromSingleStringRep (const char *, bool ignorehostname=false)
 
void setHostIsWindows (bool yn)
 
void setHostName (const char *hnm)
 
MachineCommandsetProgram (const char *pn)
 
void setRemExec (const char *sh)
 
BufferString toString (const CommandExecPars *=nullptr) const
 Only for messaging purposes. More...
 

Static Public Member Functions

static const char * defaultRemExec ()
 
static const char * getIsolationScriptFnm ()
 
static const char * odRemExecCmd ()
 
static void setDefaultRemExec (const char *s)
 
static void setIsolationScript (const char *)
 
static const char * sKeyIsolationScript ()
 
static const char * sKeyJobID ()
 
static const char * sKeyMasterHost ()
 
static const char * sKeyMasterPort ()
 
static const char * sKeyPrimaryHost ()
 
static const char * sKeyPrimaryPort ()
 
static const char * sKeyRemoteCmd ()
 
static const char * sKeyRemoteHost ()
 

Private Member Functions

void addShellIfNeeded ()
 
MachineCommand getExecCommand (const CommandExecPars *=nullptr) const
 
void setIsolated (const char *prognm)
 

Private Attributes

BufferStringSet args_
 
BufferString hname_
 
bool hostiswin_ = false
 
bool needshell_ = false
 
BufferString prognm_
 
BufferString remexec_ = defremexec_
 

Static Private Attributes

static BufferString defremexec_
 

Friends

class ::StreamProvider
 
class CommandLauncher
 

Detailed Description

Encapsulates an actual command to execute + the machine to run it on.

The default remote execution command is ssh.

<>

Constructor & Destructor Documentation

◆ MachineCommand() [1/5]

OS::MachineCommand::MachineCommand ( const char *  prognm = nullptr)
inline

◆ MachineCommand() [2/5]

OS::MachineCommand::MachineCommand ( const char *  prognm,
const BufferStringSet arguments 
)
inline

◆ MachineCommand() [3/5]

OS::MachineCommand::MachineCommand ( const char *  prognm,
const char *  arg1,
const char *  arg2 = 0,
const char *  arg3 = 0,
const char *  arg4 = 0,
const char *  arg5 = 0 
)

◆ MachineCommand() [4/5]

OS::MachineCommand::MachineCommand ( const char *  prognm,
bool  isolated 
)

◆ MachineCommand() [5/5]

OS::MachineCommand::MachineCommand ( const MachineCommand ,
bool  isolated 
)

Member Function Documentation

◆ addArg() [1/2]

MachineCommand& OS::MachineCommand::addArg ( const char *  )

◆ addArg() [2/2]

template<class T >
MachineCommand& OS::MachineCommand::addArg ( const T &  t)
inline

◆ addArgs()

MachineCommand& OS::MachineCommand::addArgs ( const BufferStringSet )

◆ addFileRedirect()

MachineCommand& OS::MachineCommand::addFileRedirect ( const char *  fnm,
int  stdcode = 0,
bool  append = false 
)

stdcode=0: '>'; stdcode=1: '1>'; stdcode=2: '2>' stdcode=3: '> fnm 2>&1'; append: '>>'; otherwise: '>'

◆ addFlag()

MachineCommand& OS::MachineCommand::addFlag ( const char *  flg,
KeyStyle  ks = NewStyle 
)
inline

◆ addKeyedArg() [1/2]

MachineCommand& OS::MachineCommand::addKeyedArg ( const char *  ky,
const char *  valstr,
KeyStyle  ks = NewStyle 
)

◆ addKeyedArg() [2/2]

template<class T >
MachineCommand& OS::MachineCommand::addKeyedArg ( const char *  ky,
const T &  t,
KeyStyle  ks = NewStyle 
)
inline

◆ addPipe()

MachineCommand& OS::MachineCommand::addPipe ( )
inline

◆ addShellIfNeeded()

void OS::MachineCommand::addShellIfNeeded ( )
private

Analyses the cmd and looks for pipes or redirects. If these are found, the cmd is converted to a shell command.

◆ args()

const BufferStringSet& OS::MachineCommand::args ( ) const
inline

◆ command()

const char* OS::MachineCommand::command ( ) const

◆ defaultRemExec()

static const char* OS::MachineCommand::defaultRemExec ( )
inlinestatic

◆ execute() [1/3]

bool OS::MachineCommand::execute ( BufferString output_stdout,
BufferString output_stderr = nullptr,
const char *  workdir = nullptr 
)

run &, wait until finished, catch output

◆ execute() [2/3]

bool OS::MachineCommand::execute ( const CommandExecPars )

◆ execute() [3/3]

bool OS::MachineCommand::execute ( LaunchType  lt = Wait4Finish,
const char *  workdir = nullptr 
)

◆ getExecCommand()

MachineCommand OS::MachineCommand::getExecCommand ( const CommandExecPars = nullptr) const
private

◆ getIsolationScriptFnm()

static const char* OS::MachineCommand::getIsolationScriptFnm ( )
static

◆ getSingleStringRep() [1/2]

const char* OS::MachineCommand::getSingleStringRep ( ) const

◆ getSingleStringRep() [2/2]

BufferString OS::MachineCommand::getSingleStringRep ( bool  noremote = false) const

◆ hasHostName()

bool OS::MachineCommand::hasHostName ( ) const
inline

◆ hostIsWindows()

bool OS::MachineCommand::hostIsWindows ( ) const
inline

◆ hostName()

const char* OS::MachineCommand::hostName ( ) const
inline

◆ isBad()

bool OS::MachineCommand::isBad ( ) const
inline

◆ odRemExecCmd()

static const char* OS::MachineCommand::odRemExecCmd ( )
inlinestatic

◆ program()

const char* OS::MachineCommand::program ( ) const
inline

◆ remExec()

const char* OS::MachineCommand::remExec ( ) const
inline

◆ runAndCollectOutput()

BufferString OS::MachineCommand::runAndCollectOutput ( BufferString errmsg = nullptr)

for quick get-me-the-output-of-this-command

◆ setCommand()

void OS::MachineCommand::setCommand ( const char *  )

◆ setDefaultRemExec()

static void OS::MachineCommand::setDefaultRemExec ( const char *  s)
inlinestatic

◆ setFromSingleStringRep()

bool OS::MachineCommand::setFromSingleStringRep ( const char *  ,
bool  ignorehostname = false 
)
Returns
!isBad(). Assumes that arguments are space separated, and command with spaces in them are properly escaped.

◆ setHostIsWindows()

void OS::MachineCommand::setHostIsWindows ( bool  yn)
inline

◆ setHostName()

void OS::MachineCommand::setHostName ( const char *  hnm)
inline

◆ setIsolated()

void OS::MachineCommand::setIsolated ( const char *  prognm)
private

◆ setIsolationScript()

static void OS::MachineCommand::setIsolationScript ( const char *  )
static

◆ setProgram()

MachineCommand& OS::MachineCommand::setProgram ( const char *  pn)
inline

◆ setRemExec()

void OS::MachineCommand::setRemExec ( const char *  sh)
inline

◆ sKeyIsolationScript()

static const char* OS::MachineCommand::sKeyIsolationScript ( )
inlinestatic

◆ sKeyJobID()

static const char* OS::MachineCommand::sKeyJobID ( )
inlinestatic

◆ sKeyMasterHost()

static const char* OS::MachineCommand::sKeyMasterHost ( )
inlinestatic

◆ sKeyMasterPort()

static const char* OS::MachineCommand::sKeyMasterPort ( )
inlinestatic

◆ sKeyPrimaryHost()

static const char* OS::MachineCommand::sKeyPrimaryHost ( )
inlinestatic

◆ sKeyPrimaryPort()

static const char* OS::MachineCommand::sKeyPrimaryPort ( )
inlinestatic

◆ sKeyRemoteCmd()

static const char* OS::MachineCommand::sKeyRemoteCmd ( )
inlinestatic

◆ sKeyRemoteHost()

static const char* OS::MachineCommand::sKeyRemoteHost ( )
inlinestatic

◆ toString()

BufferString OS::MachineCommand::toString ( const CommandExecPars = nullptr) const

Only for messaging purposes.

Friends And Related Function Documentation

◆ ::StreamProvider

friend class ::StreamProvider
friend

◆ CommandLauncher

friend class CommandLauncher
friend

Member Data Documentation

◆ args_

BufferStringSet OS::MachineCommand::args_
private

◆ defremexec_

BufferString OS::MachineCommand::defremexec_
staticprivate

◆ hname_

BufferString OS::MachineCommand::hname_
private

◆ hostiswin_

bool OS::MachineCommand::hostiswin_ = false
private

◆ needshell_

bool OS::MachineCommand::needshell_ = false
private

◆ prognm_

BufferString OS::MachineCommand::prognm_
private

◆ remexec_

BufferString OS::MachineCommand::remexec_ = defremexec_
private

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022