I would like to run a command with $ sign in it with ipcBeginProcess but I cannot get it to work. For example:
cmd = "perl -e '$i=1; print $i;'"cid = ipcBeginProcess(cmd)ipcWait(cid)ipcReadProcess(cid)
The $i seems to be replaced by empty string when I do this. I tried putting in two $ sign to "escape" the sign but it doesn't work.
Have you tried escaping the "$" by preceding it with a backslash (or perhaps two backslashes - I have not checked in this case), e.g.
cmd = "perl -e '\$i=1; print \$i;'"
;; may need this instead, uncomment if the above does not work
; cmd = "perl -e '\\$i=1; print \\$i;'"
cid = ipcBeginProcess(cmd)
I hope that this helps!
In reply to skillUser:
Thanks for the help, your commented line works, it's weird that you need double backslash to escape the $ sign. Still, I'm having trouble getting the following code to work:
cmd = "perl -e '\\$i=\"abc def\"; print \\$i;'" cid = ipcBeginProcess(cmd) ipcWait(cid) ipcReadProcess(cid)
It will complain that "Can't locate object method \"abc\" via package \"def\" (perhaps you forgot to load \"def\"?) at -e line 1.\n". I think the " sign doesn't show up when I run the command this way, thus "abc def" is not recognized as a string.
In reply to Yaosan:
Same thing as before, you may need to give a double backslash in front of the double-quote, again I have not tested it but try:
cmd = "perl -e '\\$i=\\"abc def\\"; print \\$i;'"
Hope it helps!
Hi Lawrence, thanks for the reply again. Double backslash doesn't work for quotes (it closes the string quotes prematurely), I tried triple backslash and it works! It's hard to read the input with that many backslash but it's all good now that I get it to work.