Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Language
English













SourceForge.net Logo



AProcess

 

struct AProcess : public NoCopy

This is an abstract class that represent a controlled child process. Client code can communicate with such process by supplying standard input and reading standard output. Note that while LocalProcess implements AProcess for host OS, some other derived class might choose to e.g. represent a process on remote system.

 

 

Public Method List

 

virtual void Kill() = 0

Terminates running process.

 


 

virtual bool IsRunning() = 0

Returns true if process is running.

 


 

virtual void Write(String s) = 0

Sends a text to standard input of process.

 


 

virtual bool Read(String& s) = 0

Reads data from standard output combined with standard error output. Returns true if there process was running or there are more data to be read.

 


 

virtual bool Read2(String& os, String& es)

Reads data separately from standard output combined and from standard error output. Returns true if there process was running or there are more data to be read. Usually, implementing class has to be in special mode for this to work (e.g. LocalProcess must be started with Start2).

 


 

virtual int GetExitCode() = 0

Returns an exit code of terminated process.

 


 

virtual String GetExitMessage()

In case of error, might return its text description.

 


 

virtual void CloseRead()

Closes handle to process output.

 


 

virtual void CloseWrite()

Closes handle to process input. This is useful e.g.  in case that process waits for the end of input data before processing them and providing output.

 


 

virtual void Detach()

Disconnects AProcess instance from running child process. Process continues to run while AProcess instance can be destructed.

 


 

String Get()

This utility inline function calls Read and returns the standard output of process. If anything went wrong, returns String::GetVoid().

 

 

 

 

LocalProcess

 

class LocalProcess : public AProcess

This class implements a child process of host operating system.

 

 

Public Method List

 

bool Start(const char *cmdline, const char *envptr = NULL)

Starts a new process defined by cmdline, envptr can provide a new environment for the process, if NULL, then the new process inherits caller's environment.

 


 

bool Start2(const char *cmdline, const char *envptr = NULL)

Starts a new process defined by cmdline, envptr can provide a new environment for the process, if NULL, then the new process inherits caller's environment. This variant activates mode when standard output and standard error output are read separately using Read2 method.

 


 

LocalProcess& ConvertCharset(bool b = true)

LocalProcess& NoConvertCharset()

Determines LocalProcess should convert encoding from system to application one. Default setting is true.

 

Constructor Detail

 

LocalProcess()

Default constructor.

 


 

LocalProcess(const char *cmdline, const char *envptr = NULL)

Equivalent of default constructor and then invoking Start(cmdline, envptr).

 

 

 

 

Global functions related to LocalProcess

 

int Sys(const char *cmd, String& out, bool convertcharset = true)

Runs process defined by cmd command line, returns its standard output in output.and its exit code as return value. If there was error invoking cmd, returns -1. If convertcharset is true, output is converted from system character encoding to application encoding.

 


 

String Sys(const char *cmd, bool convertcharset = true)

Runs process defined by cmd command line. If cmd was executed successfully and returned zero exit code, returns its standard output, otherwise returns String::GetVoid(). If convertcharset is true, output is converted from system character encoding to application encoding.

 

 

Last edit by koldo on 09/13/2013. Do you want to contribute?. T++