www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: const main args?

reply mimocrocodil <4denizzz gmail.com> writes:
I seen what sendmail actually changes they arguments of command line for nice
output of "ps ax" command.

May be it changes his argc/argv for this?
Aug 15 2011
parent Dan Olson <zans.is.for.cans yahoo.com> writes:
mimocrocodil <4denizzz gmail.com> writes:

 I seen what sendmail actually changes they arguments of command line for nice
output of "ps ax" command.

 May be it changes his argc/argv for this?

Yes. Some unix C programs, daemons usually, modify argv to change what ps shows. It works with D too, I tried it (but have to cast away immutable). Here is a quick demo, assuming args[0] has enough room. import std.c.string; import core.thread; void main(string[] args) { auto a = cast(char*)args[0].ptr; strcpy(a, "xyzzy"); // change ps output to list us as xyzzy Thread.sleep(dur!("seconds")(10)); } $ ps PID TTY TIME CMD 355 ttys000 0:00.01 /bin/bash --noediting -i 358 ttys000 0:00.00 xyzzy Since you have to be unsafe anyway, casting to char* from in string would be no worse than string.
Aug 20 2011