WvStreams
Public Member Functions | List of all members
WvSystem Class Reference

WvSystem is a mostly-replacement for the libc system() function call, which people usually use because of its notational convenience, not because it calls the Unix shell. More...

#include <wvsystem.h>

Inheritance diagram for WvSystem:
Inheritance graph
[legend]

Public Member Functions

 WvSystem (const char cmd[], const char *a0=NULL, const char *a1=NULL, const char *a2=NULL, const char *a3=NULL, const char *a4=NULL, const char *a5=NULL, const char *a6=NULL, const char *a7=NULL, const char *a8=NULL, const char *a9=NULL, const char *a10=NULL, const char *a11=NULL, const char *a12=NULL, const char *a13=NULL, const char *a14=NULL, const char *a15=NULL, const char *a16=NULL, const char *a17=NULL, const char *a18=NULL, const char *a19=NULL)
 Construct a WvSystem from a simple list of strings. More...
 
 WvSystem (const char *const *argv)
 Construct a WvSystem from an argv array. More...
 
virtual ~WvSystem ()
 Destroy the WvSystem object. More...
 
int go ()
 Explicitly start the command running and wait for it to finish. More...
 
WvSysteminfile (WvStringParm filename)
 Redirect stdin from the given input file.
 
WvSystemoutfile (WvStringParm filename)
 Redirect stdout to the given output file, which is overwritten.
 
WvSystemerrfile (WvStringParm filename)
 Redirect stderr to the given output file, which is overwritten.
 

Detailed Description

WvSystem is a mostly-replacement for the libc system() function call, which people usually use because of its notational convenience, not because it calls the Unix shell.

In fact, some people don't even realize it calls the shell, leading to security holes when people forget to quote user-provided parameters correctly.

WvSystem() uses WvSubProc but makes sure it can be called in a single line of C++ code with a minimum of fluff. For example:

WvSystem("rm", "-rf", filename, NULL); is like system(WvString("rm -rf %s", filename)); except that you don't have weird security bugs if "filename" contains special characters like newline, space, quotation mark, etc.

See WvSubProc and WvSubProcQueue for less concise, but more flexible ways to run subprograms.

Definition at line 29 of file wvsystem.h.

Constructor & Destructor Documentation

◆ WvSystem() [1/2]

WvSystem::WvSystem ( const char  cmd[],
const char *  a0 = NULL,
const char *  a1 = NULL,
const char *  a2 = NULL,
const char *  a3 = NULL,
const char *  a4 = NULL,
const char *  a5 = NULL,
const char *  a6 = NULL,
const char *  a7 = NULL,
const char *  a8 = NULL,
const char *  a9 = NULL,
const char *  a10 = NULL,
const char *  a11 = NULL,
const char *  a12 = NULL,
const char *  a13 = NULL,
const char *  a14 = NULL,
const char *  a15 = NULL,
const char *  a16 = NULL,
const char *  a17 = NULL,
const char *  a18 = NULL,
const char *  a19 = NULL 
)
inline

Construct a WvSystem from a simple list of strings.

For example: WvSystem("rm", "-rf", dirname);

Note: this is unlike WvSubProc::prepare(cmd, ...) because you don't need to provide argv[0] yourself. "cmd" is automatically inserted as argv[0]. It also lets you pass WvString objects in without manually calling cstr(), because it doesn't use varargs. Unfortunately, that means it's limited to 20 arguments.

Definition at line 44 of file wvsystem.h.

◆ WvSystem() [2/2]

WvSystem::WvSystem ( const char *const *  argv)
inline

Construct a WvSystem from an argv array.

This is exactly the same as WvSubProc's argv[] constructor, but the command name is always taken from argv[0] rather than provided separately.

For example: const char *argv[] = { "rm", "-rf", dirname, NULL }; WvSystem(argv);

Definition at line 86 of file wvsystem.h.

◆ ~WvSystem()

WvSystem::~WvSystem ( )
virtual

Destroy the WvSystem object.

If you haven't yet called go(), the command is run before destruction.

Definition at line 12 of file wvsystem.cc.

References go().

Member Function Documentation

◆ go()

int WvSystem::go ( )

Explicitly start the command running and wait for it to finish.

This will happen automatically at object destruction time, but if you want to check the return code, you'll need to call go().

Definition at line 59 of file wvsystem.cc.

Referenced by ~WvSystem().


The documentation for this class was generated from the following files: