Ingo Feinerer <feine...@logic.at> writes:

> Hi,

Hi Ingo,

> when running
>
> R --file=~/test.R --args -i -j -k
>
> with R from math/R in ports and test.R as
>
> commandArgs(TRUE)
> Sys.sleep(10)
>
> ps output displays
>
> /usr/local/lib/R/bin/exec/R --file=/home/user/test.R --args --args --args 
> --args
>
> (Note the four --args.) However, R appears to have the right arguments
> (the first --args is deliberately ignored by R):
>
> R> commandArgs(TRUE)
> [1] "-i" "-j" "-k"
>
> Any ideas why the display of the arguments in ps differs from the
> command line?

One possible explanation is that R modifies its original argv[] in place.

--8<--
#include <unistd.h>

int
main(int argc, char *argv[])
{
        if (argc < 2)
                return 1;

        argv[1] = "new-argv[1]";

        sleep(20);

        return 0;
}
-->8--

If you launch ./r some-arg you'll see "new-argv[1]" in ps(1) output.
As a side note this doesn't happen on Linux thus some projects don't
care much about the possible breakage on OpenBSD (see the pexp in
net/geomyidae/pkg/geomyidae.rc).

> With a simple shell script I cannot reproduce this. E.g.,
>
> ./test.sh --args -i -j -k
>
> with test.sh as
>
> #!/bin/sh

*

> echo $@
> sleep 10
>
> results in ps displaying
>
> /bin/sh ./test.sh --args -i -j -k

ksh doesn't do weird stuff like that, at least...

* you could insert ''set -- --args --args --args --args'' here, to
  replace the original arguments, ksh wouldn't modify argv either.

> Best regards,
> Ingo
>

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to