how to run system command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

how to run system command

sagarnikam123
i run like ,but it giving other than what i expect
i also want to capture output & print it

> e<-system("date")
> e
[1] 127

----------------------------------------------------------------------------
> e<-system("dir")
> e
[1] 127
Sagar Nikam
B.Pharm, M.Sc(Bioinformatics)
Software Engineer (Data Research Analyst )
Trendwise Analytics,Bangalore
India
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Sarah Goslee
Please read the help for system, paying particular attention to the
intern argument.

> e <- system("date", intern=TRUE)
> e
[1] "Tue Mar  6 08:33:48 EST 2012"


Sarah

On Tue, Mar 6, 2012 at 6:56 AM, sagarnikam123 <[hidden email]> wrote:

> i run like ,but it giving other than what i expect
> i also want to capture output & print it
>
>> e<-system("date")
>> e
> [1] 127
>
> ----------------------------------------------------------------------------
>> e<-system("dir")
>> e
> [1] 127
>

--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Michael Weylandt
In reply to this post by sagarnikam123
Those are error messages from the shell, not "real values" for what
you think you are doing. Are you looking for the getwd() and
Sys.date() functions instead?

Michael

On Tue, Mar 6, 2012 at 6:56 AM, sagarnikam123 <[hidden email]> wrote:

> i run like ,but it giving other than what i expect
> i also want to capture output & print it
>
>> e<-system("date")
>> e
> [1] 127
>
> ----------------------------------------------------------------------------
>> e<-system("dir")
>> e
> [1] 127
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-run-system-command-tp4449597p4449597.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

sagarnikam123
In reply to this post by Sarah Goslee
i used it on windows system, but giving error like

> e <- system("date", intern=TRUE)
Error in system("date", intern = TRUE) : 'date' not found
Sagar Nikam
B.Pharm, M.Sc(Bioinformatics)
Software Engineer (Data Research Analyst )
Trendwise Analytics,Bangalore
India
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Sarah Goslee
On Tue, Mar 6, 2012 at 8:48 AM, sagarnikam123 <[hidden email]> wrote:
> i used it on windows system, but giving error like
>
>> e <- system("date", intern=TRUE)
> Error in system("date", intern = TRUE) : 'date' not found

If you type date at a windows command line does it work?

You can't use system() to run system commands that don't
exist on your system. I don't run windows, and have no
idea what the command/syntax to obtain the date might be.

It was already suggested you use Sys.Date() instead, and
only use system() for system commands not duplicated in R.

Sarah-


--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

William Dunlap
In reply to this post by sagarnikam123
> system("cmd.exe /c date /T", intern=TRUE)
[1] "Tue 03/06/2012 "

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of sagarnikam123
> Sent: Tuesday, March 06, 2012 5:49 AM
> To: [hidden email]
> Subject: Re: [R] how to run system command
>
> i used it on windows system, but giving error like
>
> > e <- system("date", intern=TRUE)
> Error in system("date", intern = TRUE) : 'date' not found
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-run-system-command-
> tp4449597p4449906.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Henrik Bengtsson-3
On Tue, Mar 6, 2012 at 11:49 AM, William Dunlap <[hidden email]> wrote:
>> system("cmd.exe /c date /T", intern=TRUE)
> [1] "Tue 03/06/2012 "

To avoid messing with "cmd.exe /c", you can use shell(), e.g.

> res <- shell("date /T", intern=TRUE)
> res
[1] "Tue 03/06/2012 "


>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of sagarnikam123
>> Sent: Tuesday, March 06, 2012 5:49 AM
>> To: [hidden email]
>> Subject: Re: [R] how to run system command
>>
>> i used it on windows system, but giving error like
>>
>> > e <- system("date", intern=TRUE)
>> Error in system("date", intern = TRUE) : 'date' not found
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/how-to-run-system-command-
>> tp4449597p4449906.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Keith Jewell
In reply to this post by sagarnikam123
Works for me:
--------------------------
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United
Kingdom.1252

attached base packages:
 [1] grDevices datasets  splines   graphics  stats     tcltk     utils
tools     methods   base

other attached packages:
[1] CBRIutils_1.0    stringr_0.5      svSocket_0.9-51  TinnR_1.0.3
R2HTML_2.2       Hmisc_3.8-3      survival_2.36-10

loaded via a namespace (and not attached):
[1] cluster_1.14.1 grid_2.14.1    lattice_0.20-0 plyr_1.7.1
svMisc_0.9-63
> e <- system("date", intern=TRUE)
> e
[1] "Wed Mar  7 08:58:32 GMTST 2012"
----------------

What's your sessionInfo()?

KJ


"sagarnikam123" <[hidden email]> wrote in message
news:[hidden email]...

>i used it on windows system, but giving error like
>
>> e <- system("date", intern=TRUE)
> Error in system("date", intern = TRUE) : 'date' not found
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/how-to-run-system-command-tp4449597p4449906.html
> Sent from the R help mailing list archive at Nabble.com.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

William Dunlap
You wrote:
  > Works for me:
  >> e <- system("date", intern=TRUE)
  >> e
  >[1] "Wed Mar  7 08:58:32 GMTST 2012"
I suspect you have cygwin\bin in your PATH variable,
as that does not look like Windows date command:
  > system("cmd.exe /c date /T")
  Wed 03/07/2012
  > shell("date /T")  
  Wed 03/07/2012
  > shell("date") # asks for new date if no /T
  The current date is: Wed 03/07/2012
  Enter the new date: (mm-dd-yy) Warning messages:
  1: running command 'C:\Windows\system32\cmd.exe /c date' had status 1
  2: In shell("date") : 'date' execution failed with error code 1
 
sessionInfo() does not report PATH's contents.  You can
look at it with
   strsplit(Sys.getenv("PATH"), .Platform$path.sep)[[1]]

Bill Dunlap

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Keith Jewell
> Sent: Wednesday, March 07, 2012 1:02 AM
> To: [hidden email]
> Subject: Re: [R] how to run system command
>
> Works for me:
> --------------------------
> > sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
> Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C                            LC_TIME=English_United
> Kingdom.1252
>
> attached base packages:
>  [1] grDevices datasets  splines   graphics  stats     tcltk     utils
> tools     methods   base
>
> other attached packages:
> [1] CBRIutils_1.0    stringr_0.5      svSocket_0.9-51  TinnR_1.0.3
> R2HTML_2.2       Hmisc_3.8-3      survival_2.36-10
>
> loaded via a namespace (and not attached):
> [1] cluster_1.14.1 grid_2.14.1    lattice_0.20-0 plyr_1.7.1
> svMisc_0.9-63
> > e <- system("date", intern=TRUE)
> > e
> [1] "Wed Mar  7 08:58:32 GMTST 2012"
> ----------------
>
> What's your sessionInfo()?
>
> KJ
>
>
> "sagarnikam123" <[hidden email]> wrote in message
> news:[hidden email]...
> >i used it on windows system, but giving error like
> >
> >> e <- system("date", intern=TRUE)
> > Error in system("date", intern = TRUE) : 'date' not found
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/how-to-run-system-command-
> tp4449597p4449
> > 906.html Sent from the R help mailing list archive at Nabble.com.
> >
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: how to run system command

Keith Jewell
Yes, not cygwin\bin but Rtools\bin (which is in my path:)
> Sys.which("date")
                          date
"Z:\\R\\Rtools\\bin\\date.exe"

The OP's error message (Error in system("date", intern = TRUE) : 'date' not
found) suggests he has no 'date' in his path.
I see ?system says "DOS internal commands, ... cannot be used: see shell",
so you and others are correct in recommending 'shell' rather than 'system'.

Sorry for the noise :-(
At least I've learned something :-)

Best regards,

KJ

"William Dunlap" <[hidden email]> wrote in message
news:[hidden email]...

> You wrote:
>  > Works for me:
>  >> e <- system("date", intern=TRUE)
>  >> e
>  >[1] "Wed Mar  7 08:58:32 GMTST 2012"
> I suspect you have cygwin\bin in your PATH variable,
> as that does not look like Windows date command:
>  > system("cmd.exe /c date /T")
>  Wed 03/07/2012
>  > shell("date /T")
>  Wed 03/07/2012
>  > shell("date") # asks for new date if no /T
>  The current date is: Wed 03/07/2012
>  Enter the new date: (mm-dd-yy) Warning messages:
>  1: running command 'C:\Windows\system32\cmd.exe /c date' had status 1
>  2: In shell("date") : 'date' execution failed with error code 1
>
> sessionInfo() does not report PATH's contents.  You can
> look at it with
>   strsplit(Sys.getenv("PATH"), .Platform$path.sep)[[1]]
>
> Bill Dunlap
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]]
>> On
>> Behalf Of Keith Jewell
>> Sent: Wednesday, March 07, 2012 1:02 AM
>> To: [hidden email]
>> Subject: Re: [R] how to run system command
>>
>> Works for me:
>> --------------------------
>> > sessionInfo()
>> R version 2.14.1 (2011-12-22)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
>> Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
>> [4] LC_NUMERIC=C                            LC_TIME=English_United
>> Kingdom.1252
>>
>> attached base packages:
>>  [1] grDevices datasets  splines   graphics  stats     tcltk     utils
>> tools     methods   base
>>
>> other attached packages:
>> [1] CBRIutils_1.0    stringr_0.5      svSocket_0.9-51  TinnR_1.0.3
>> R2HTML_2.2       Hmisc_3.8-3      survival_2.36-10
>>
>> loaded via a namespace (and not attached):
>> [1] cluster_1.14.1 grid_2.14.1    lattice_0.20-0 plyr_1.7.1
>> svMisc_0.9-63
>> > e <- system("date", intern=TRUE)
>> > e
>> [1] "Wed Mar  7 08:58:32 GMTST 2012"
>> ----------------
>>
>> What's your sessionInfo()?
>>
>> KJ
>>
>>
>> "sagarnikam123" <[hidden email]> wrote in message
>> news:[hidden email]...
>> >i used it on windows system, but giving error like
>> >
>> >> e <- system("date", intern=TRUE)
>> > Error in system("date", intern = TRUE) : 'date' not found
>> >
>> > --
>> > View this message in context:
>> > http://r.789695.n4.nabble.com/how-to-run-system-command-
>> tp4449597p4449
>> > 906.html Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.