MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: shell command

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2823] Re: shell command
  • From: villegas (Robert Villegas)
  • Date: Sat, 23 Dec 1995 03:16:59 -0500
  • Organization: Wolfram Research, Inc.

In article <4b859g$app at dragonfly.wri.com> Susan Rempe  
<rempe at euclid.chem.washington.edu> writes:


> Running Mma on a unix machine, how does one
> execute a shell command like "cd temp"?


You can use Run, giving the OS command as a string:


In[19]:= Run["pwd"]
/private/tmp

Out[19]= 0

In[20]:= Run["ls"]
adim.pid                m000001000520           openfiletmp001248
console.log             m000001000976           selection.in
m000001000344           m000001001154           villegas
m000001000461           m000001002030
m000001000489           m000001004162

Out[20]= 0


Or just type an exclamation point followed by the command string:

In[21]:= !pwd
/private/tmp

The exclamation point needs to be the first character in the input
string.


You may not know this:  when you issue an OS command such as 'ls'
or 'cd temp', it is executed in a subshell that is spawned by
Mathematica just for that one command.  Once the command is finished,
the subshell is exited.  If your command was to change something
about the shell environment, such as the current working directory,
then it will take effect in that temporary subshell and then be gone,
so it won't be of any use to you.

I suspect you want to change the environment of your Mathematica session
so you can work with files.  Use one of the built-in file/OS commands
instead:

In[21]:= SetDirectory["/tmp"]  

Out[21]= /private/tmp

In[22]:= FileNames[]

Out[22]= {adim.pid, console.log, m000001000344, m000001000461, m000001000489, 
 
>    m000001000520, m000001000976, m000001001154, m000001002030, 
 
>    m000001004162, openfiletmp001248, selection.in, villegas}


Robby Villegas


  • Prev by Date: Re: Programming
  • Next by Date: Re: LISTS and more LISTS
  • Previous by thread: shell command
  • Next by thread: Mma speed trials (Win'95)