Yes, but the details depend on your OS.
Under windows, you can use the dos() function. You need to make sure that
your have perl in your PATH variable.
The S-PLUS dos function passes the command string to the windows command
line evaluator.
Here's two very simple examples to get started:
> dos("perl -e 'print 1'")
character(0)
> dos("perl -v")
[1]
""
[2] "This is perl, v5.6.1 built for
MSWin32-x86-multi-thread"
[3] "(with 1 registered patch, see perl -V for more
detail)"
[4]
""
[5] "Copyright 1987-2001, Larry
Wall"
[6]
""
[7] "Binary build 635 provided by ActiveState Corp.
http://www.ActiveState.com"
[8] "Built 15:34:21 Feb 4
2003"
[9]
""
[10]
""
[11] "Perl may be copied only under the terms of either the Artistic
License or the"
[12] "GNU General Public License, which may be found in the Perl 5 source
kit."
[13]
""
[14] "Complete documentation for Perl, including FAQ lists, should be found
on"
[15] "this system using `man perl' or `perldoc perl'. If you have access
to the"
[16] "Internet, point your browser at http://www.perl.com/, the Perl Home
Page."
[17]
""
> dos("perl -e \"print 1\"")
[1] "1"
>
Quoting strings in "-e" commnads so that they get passed properly to perl
is challenging. (I'm not sure it can actually be done when there is any
level of nesting, and it probably differs among versions of
windows.) Whenever the windows command line processor cannot process the
command successfuly, either because it can't find the command, or because
it can't grok the quoting, the dos() function returns an empty length
character vector. E.g., here's a failed attempt to print a string.
> dos("perl -e \"print 'hello world'\"")
character(0)
> dos("perlnot -e \"print 1\"")
character(0)
Some versions (I don't think all, but I'm not positive about that) of the
windows command line processor understand "2>&1", which can provide more
informative messages, e.g.,:
> dos("perl -e \"print 'hello world'\" 2>&1")
[1] "Can't find string terminator \"'\" anywhere before EOF at -e line 1."
> dos("perlnot -e \"print 1\" 2>&1")
[1] "'perlnot' is not recognized as an internal or external command,"
[2] "operable program or batch file."
>
The quoting issues of course that for most perl programs, it's probably
better to put the program in a file and pass the name of that file to perl
with the -f option. If you're really keen on inline programs, you can
explore perl's quoting functions, e.g.:
> dos("perl -e \"print q{hello world}\" 2>&1")
[1] "hello world"
>
If you're stuck at the point of not even being able to find the perl
program, check what PATH is getting passed:
> dos("PATH")
[1] "PATH=C:\\Program Files\\Insightful\\splus61\\/cmd;...
The documentation for the S-PLUS dos() function should of course be read
some time during attempting this type of thing.
-- Tony Plate
At Thursday 07:03 AM 12/23/2004, Joe Cerniglia wrote:
Is it possible to run a perl script from splus?
Thanks in advance.
Joe
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|