Skip to content

multiline system call

7 messages · Nicolas Mazziotta, Charles C. Berry, Gabor Grothendieck +1 more

#
Hello,

I am trying to call sendmail from within R via system(). As sendmail reads 
from STDIN, I need to pass a multiline input as an argument.

E.g. (not working):

	system('sendmail -f xxx at swing.be -t yyy at swing.be\ntest\n.\n')

I tried a lot of ways to type the EOL characters, but cannot get them work the 
right way. This leads to several problems. For instance, R waits for me to 
enter <control-D> at the end of the sequence.

Thanks for any help.
#
Look at the help page for ?system, especially the  'input=' arg.

Maybe this sort of strategy will fly:
[1] "x" "y"
In your case, maybe

system('sh' input=c('sendmail -f xxx at swing.be -t yyy at swing.be','test','.')

or

system('sendmail -f xxx at swing.be -t yyy at swing.be', input='test')

will do it.
On Fri, 22 Dec 2006, Nicolas Mazziotta wrote:

            
Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0717
#
Dear Sir,

Le vendredi 22 d?cembre 2006 20:05, vous avez ?crit :
Thanks for the advice, but I do not find doc about the input arg for the 
system function. Besides,

$> system("sh",intern=T,input=c("echo x","echo y"))
Erreur dans system("sh", intern = T, input = c("echo x", "echo y")) :
        unused argument(s) (input = c("echo x", "echo y"))

Is R version 2.4.0 (2006-10-03) too old?

Best regards,
#
Its only available on Windows.
On 12/22/06, Nicolas Mazziotta <nicolas.mazziotta at swing.be> wrote:
#
On Fri, 22 Dec 2006, Gabor Grothendieck wrote:

            
Right, but on linux this works
[1] "x" "y"
[1] "x" "y"

so you don't really need input=...

But rereading Nicolas original post, it looks like the problem is 
terminating the input with a ctrl-D.

Perhaps a workaround is to pipe the input into sendmail (I recall sendmail 
accepts input from sdtin) from 'echo'

Note that the single quotes are needed to protect the '\n's until echo is 
ready to act:
[1] "      3       3      10"
I have exim - not sendmail, but this sends a msg from/to me on my linux 
box:

system("echo 'To:cberry\nthis is a test' | /usr/sbin/exim -f cberry at tajo.ucsd.edu -t "

Maybe this will work for Nicolas.
Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0717
#
Le vendredi 22 d?cembre 2006 23:31, Charles C. Berry a ?crit?:
This works fine this way. Thanks a lot.

(but note that my 2.4.0 linux binary does not accept the "input=xyz" as an 
argument of the system() function.)
#
On Sat, 23 Dec 2006, Nicolas Mazziotta wrote:

            
Nor should it, but you failed to tell us what your OS was, and it matters 
in this query (as in many others) which is why the posting guide asked 
you to supply such information.

system() differs fundamentally by OS: it uses a shell on Unix-alikes but 
not on Windows.