quoting quotes, &c.

J

jsnX

if i wanted to call system with an argument to a function that had
double quotes and backslashes in it - for example

perl -e 'print "hello world\n"; '

how would i make that work? would it be:

std::system("perl -e 'print \"hello world\\n\"; ' ");

? are there other ways?
 
V

Victor Bazarov

jsnX said:
if i wanted to call system with an argument to a function that had
double quotes and backslashes in it - for example

perl -e 'print "hello world\n"; '

how would i make that work? would it be:

std::system("perl -e 'print \"hello world\\n\"; ' ");

?

Does it work for you? If it does, why ask "would it be"? If it does
not, what happens?

'system' function accepts a string that is passed in an implementation-
defined way to the host platform. Nothing beyond that is specified.
To add a backslash to a string literal, you need to double it. To add
a double quote, you need to escape it with a backslash.
are there other ways?

Yes, there are probably other ways, platform-specific, no doubt. In what
sense "other"? A different way to represent double quotes? Yes, you can
use the \xHH notation where HH is the value in the host character set,
representing the double quotation character, and you can use the same for
the backslash... Is that what you're asking for?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top