E-MailRelay
Classes | Public Member Functions | Static Public Member Functions | List of all members
G::BatchFile Class Reference

A class for reading and writing windows-style startup batch files containing a single command-line, optionally using "start". More...

#include <gbatchfile.h>

Public Member Functions

 BatchFile (const Path &)
 Constructor that reads from a file. More...
 
 BatchFile (const Path &, std::nothrow_t)
 Constructor that reads from a file that might be missing or empty. More...
 
std::string line () const
 Returns the main command-line from within the batchfile, with normalised spaces, without any "start" prefix, and including quotes. More...
 
bool empty () const
 Returns true if line() is empty. More...
 
std::string name () const
 Returns the "start" window name, if any. More...
 
const StringArrayargs () const
 Returns the startup command-line broken up into de-quoted pieces. More...
 
std::size_t lineArgsPos () const
 Returns the position in line() where the arguments start. More...
 

Static Public Member Functions

static void write (const Path &new_batch_file, const StringArray &args, const std::string &start_window_name={}, bool do_backup=false)
 Writes a startup batch file, including a "start" prefix. More...
 

Detailed Description

A class for reading and writing windows-style startup batch files containing a single command-line, optionally using "start".

Eg:

@echo off
rem a windows batch file
start "my app" "c:\my app\run.exe" arg-one "arg two"

Batch files always use the OEM code page on Windows but at this interface it's all UTF-8.

Definition at line 52 of file gbatchfile.h.

Constructor & Destructor Documentation

◆ BatchFile() [1/2]

G::BatchFile::BatchFile ( const Path path)
explicit

Constructor that reads from a file.

Definition at line 32 of file gbatchfile.cpp.

◆ BatchFile() [2/2]

G::BatchFile::BatchFile ( const Path path,
std::nothrow_t   
)

Constructor that reads from a file that might be missing or empty.

The line() will be empty if construction fails.

Definition at line 37 of file gbatchfile.cpp.

Member Function Documentation

◆ args()

const G::StringArray & G::BatchFile::args ( ) const

Returns the startup command-line broken up into de-quoted pieces.

The first item in the list will be the executable.

Definition at line 176 of file gbatchfile.cpp.

◆ empty()

bool G::BatchFile::empty ( ) const

Returns true if line() is empty.

Definition at line 72 of file gbatchfile.cpp.

◆ line()

std::string G::BatchFile::line ( ) const

Returns the main command-line from within the batchfile, with normalised spaces, without any "start" prefix, and including quotes.

Definition at line 166 of file gbatchfile.cpp.

◆ lineArgsPos()

std::size_t G::BatchFile::lineArgsPos ( ) const

Returns the position in line() where the arguments start.

Definition at line 181 of file gbatchfile.cpp.

◆ name()

std::string G::BatchFile::name ( ) const

Returns the "start" window name, if any.

Definition at line 171 of file gbatchfile.cpp.

◆ write()

void G::BatchFile::write ( const Path new_batch_file,
const StringArray args,
const std::string &  start_window_name = {},
bool  do_backup = false 
)
static

Writes a startup batch file, including a "start" prefix.

If the "start" window name is not supplied then it is derived from the command-line. The 'args' must not contain double-quote characters. The first 'args' item is the target executable.

Definition at line 204 of file gbatchfile.cpp.


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