digitalmars.D.learn - passing a string with the & character as an argument
- jic (23/23) Feb 28 2012 Greetings!
- James Miller (12/35) Feb 28 2012 This is more a shell problem than a D one. Assuming that you are using
- Jos van Uden (5/31) Feb 28 2012 On windows the ampersand also has a special meaning. In that case
- James Miller (4/38) Feb 28 2012 Today I Learned that windows has insane escaping.
- jic (2/47) Feb 29 2012 Me too. I tried escaping it with the wonder-working \, but that didn't ...
- Andrej Mitrovic (3/4) Feb 29 2012 You won't have to worry about it for long:
Greetings! I have this program, import std.process : system; import std.stdio; int main(char[][] args) { char[] cmd; for (int i=1;i<args.length;i++) { cmd ~= args[i] ~ " "; } writefln(cmd); return(1); } if I compile it and run it this way, the result is 1! 2 3 So, if I pass a string with an &, the argument array stops right before the &. How can I pass a & in a string? I tried escaping it, but it does not work either. thanks for the help. jic
Feb 28 2012
On 29 February 2012 18:51, jic <cabrera wrc.xerox.com> wrote:Greetings! I have this program, import std.process : system; import std.stdio; int main(char[][] args) { =C2=A0char[] cmd; =C2=A0for (int i=3D1;i<args.length;i++) =C2=A0{ =C2=A0 =C2=A0cmd ~=3D args[i] ~ " "; =C2=A0} =C2=A0writefln(cmd); =C2=A0return(1); } if I compile it and run it this way, the result is 1! 2 3 So, if I pass a string with an &, the argument array stops right before the &. =C2=A0How can I pass a & in a string? =C2=A0I tried escapin=g it,but it does not work either. thanks for the help. jicThis is more a shell problem than a D one. Assuming that you are using a *nix shell (so csh, tcsh, bash or zsh) you need escape the & with a backslash, like so: \&. You should be getting an error on your shell, Its because '&' is a special character used to fork a process into the background, useful for gui programs and the like. I have tried your code, using a *nix shell, and using 3\& works. If you are on Windows, then I don't know why this is happening. -- James Miller
Feb 28 2012
On 29-2-2012 7:06, James Miller wrote:On 29 February 2012 18:51, jic<cabrera wrc.xerox.com> wrote:Greetings! I have this program, import std.process : system; import std.stdio; int main(char[][] args) { char[] cmd; for (int i=1;i<args.length;i++) { cmd ~= args[i] ~ " "; } writefln(cmd); return(1); } if I compile it and run it this way, the result isIf you are on Windows, then I don't know why this is happening.On windows the ampersand also has a special meaning. In that case try the carrot ^ to escape Jos
Feb 28 2012
On 29 February 2012 20:21, Jos van Uden <user domain.invalid> wrote:On 29-2-2012 7:06, James Miller wrote:Today I Learned that windows has insane escaping. -- James MillerOn 29 February 2012 18:51, jic<cabrera wrc.xerox.com> =C2=A0wrote:Greetings! I have this program, import std.process : system; import std.stdio; int main(char[][] args) { =C2=A0char[] cmd; =C2=A0for (int i=3D1;i<args.length;i++) =C2=A0{ =C2=A0 =C2=A0cmd ~=3D args[i] ~ " "; =C2=A0} =C2=A0writefln(cmd); =C2=A0return(1); } if I compile it and run it this way, the result isIf you are on Windows, then I don't know why this is happening.On windows the ampersand also has a special meaning. In that case try the carrot ^ to escape Jos
Feb 28 2012
James Miller Wrote:On 29 February 2012 20:21, Jos van Uden <user domain.invalid> wrote:Me too. I tried escaping it with the wonder-working \, but that didn't work. This does work. Weird stuff... Thanks all.On 29-2-2012 7:06, James Miller wrote:Today I Learned that windows has insane escaping.On 29 February 2012 18:51, jic<cabrera wrc.xerox.com> wrote:Greetings! I have this program, import std.process : system; import std.stdio; int main(char[][] args) { char[] cmd; for (int i=1;i<args.length;i++) { cmd ~= args[i] ~ " "; } writefln(cmd); return(1); } if I compile it and run it this way, the result isIf you are on Windows, then I don't know why this is happening.On windows the ampersand also has a special meaning. In that case try the carrot ^ to escape Jos
Feb 29 2012
On 2/29/12, James Miller <james aatch.net> wrote:Today I Learned that windows has insane escaping.You won't have to worry about it for long: https://github.com/D-Programming-Language/phobos/pull/457
Feb 29 2012