libs/stream_message/src/startprocess.cxx
// defined(_WIN32)
// ===========================================================================
// To pass command arguments on Windows, it is necessary to transform a
// list of strings into a single string.
//
// The arguments are concatenated, with spaces inserted as separators.
// Arguments that contains spaces are double-quoted.
// Quotes are escaped using a backslash.
// Note that unlike C strings, a single backslash represents itself.
// If this procedure were applied to an argument which contained a space
// and whose final character was a backslash, the transformed result
// contains a backslash-quote combination, which is interpreted by
// Windows as an escaped double-quote.  Therefore we advance the quote
// to follow the last non-backslash character.
// 
defined(_WIN32)
To pass command arguments on Windows, it is necessary to transform a
list of strings into a single string.

The arguments are concatenated, with spaces inserted as separators.
Arguments that contains spaces are double-quoted.
Quotes are escaped using a backslash.
Note that unlike C strings, a single backslash represents itself.
If this procedure were applied to an argument which contained a space
and whose final character was a backslash, the transformed result
contains a backslash-quote combination, which is interpreted by
Windows as an escaped double-quote.  Therefore we advance the quote
to follow the last non-backslash character.
defined ( _WIN32 ) To pass command arguments on Windows it is necessary to transform a list of strings into a single string . The arguments are concatenated with spaces inserted as separators . Arguments that contains spaces are double - quoted . Quotes are escaped using a backslash . Note that unlike C strings a single backslash represents itself . If this procedure were applied to an argument which contained a space and whose final character was a backslash the transformed result contains a backslash - quote combination which is interpreted by Windows as an escaped double - quote . Therefore we advance the quote to follow the last non - backslash character .
string MBDriver::prepare_command_arguments(const list<string> &args)
{
    string result;
    int arg_count = 0;
    list<string>::const_iterator iter;
    for (iter = args.begin(); iter != args.end(); ++iter) {
	string arg = *iter;
	string::size_type n = 0;
	for (;;) {
	    string::size_type where = arg.find("\"", n);
	    if (where == string::npos) {
		break;
	    }
	    arg.replace(where, 1, "\\\"");
	    n = where + 2;
	}
	if (arg.find(" ") != string::npos || arg.length() == 0
		|| arg.find("%") != string::npos) {
	    string::size_type end_quote = arg.find_last_not_of('\\');
	    arg.insert(end_quote == string::npos ? 0 : end_quote + 1, 1, '"');
	    arg.insert(string::size_type(0), 1, '"');
	}
	if (arg_count > 0) {
	    result.append(1, ' ');
	}
	result.append(arg);
	arg_count += 1;
    }
    return result;
}
string MBDriver :: prepare_command_arguments ( const list < string > & args ) { string result ; int arg_count = 0 ; list < string > :: const_iterator iter ; for ( iter = args . begin ( ) ; iter != args . end ( ) ; ++ iter ) { string arg = * iter ; string :: size_type n = 0 ; for ( ; ; ) { string :: size_type where = arg . find ( " \" " , n ) ; if ( where == string :: npos ) { break ; } arg . replace ( where , 1 , " \\ \" " ) ; n = where + 2 ; } if ( arg . find ( " " ) != string :: npos || arg . length ( ) == 0 || arg . find ( " " ) != string :: npos ) { string :: size_type end_quote = arg . find_last_not_of ( ' \\ ' ) ; arg . insert ( end_quote == string :: npos ? 0 : end_quote + 1 , 1 , ' ' ) ; arg . insert ( string :: size_type ( 0 ) , 1 , ' ' ) ; } if ( arg_count > 0 ) { result . append ( 1 , ' ' ) ; } result . append ( arg ) ; arg_count += 1 ; } return result ; }
defined(_WIN32)
To pass command arguments on Windows, it is necessary to transform a
list of strings into a single string.
defined ( _WIN32 ) To pass command arguments on Windows it is necessary to transform a list of strings into a single string .
// Escape the double-quotes. // Quote the spaces. // Quotes are used for %'s not because they are strictly required, // but because parsercmd has an unusual need for this.