<DIV>Dear Danny,</DIV>
<DIV>thank you very much for your kind answer.</DIV>
<DIV>Besides&nbsp;solving properly the first part of the problem, you undirectly gave me some hints.</DIV>
<DIV>The program, modified as you suggested, works properly.</DIV>
<DIV>The fact is that the function copy was an example just to make things easier to understand.</DIV>
<DIV>The command I want to launch is "R language" a powerful statistical application, the&nbsp;parameters are built-in functions of R language.</DIV>
<DIV>Maybe this is too difficult to do just with the python function 'popen'&nbsp;.</DIV>
<DIV>In fact I tried:</DIV>
<DIV>&nbsp;</DIV>
<DIV>****************************************</DIV>
<DIV>import os<BR>os.chdir('C:\\Programmi\\R\\rw1090\\miei_files')<BR>cmd = '.RData --slave --no -save'<BR>parameters="q()"<BR>myCmd=os.popen("%s %s" % (cmd, parameters))<BR>exitCode = myCmd.close()<BR>if exitCode:<BR>&nbsp;&nbsp;&nbsp; print '%s failed, this probably says why:\n%s' % (cmd, stdout)</DIV>
<DIV>****************************************</DIV>
<DIV>and the R language gui application opens properly, but the q() function (that should close the gui) doesn't seem to be invoked.</DIV>
<DIV>How can I get the system reply when I launch a command?</DIV>
<DIV>&nbsp;</DIV>
<DIV>However as you suggested, maybe it's better to look if someone has already built the wheel, and in fact I found that there are two python packages: </DIV>
<DIV>Rpy&nbsp;and RSPython.</DIV>
<DIV>that deal with R language</DIV>
<DIV>I will try to make use of them.</DIV>
<DIV>I wonder, have you never heard about them?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks again, </DIV>
<DIV>cheers,</DIV>
<DIV>Fulvio.<BR><BR><B><I>Danny Yoo &lt;dyoo@hkn.eecs.berkeley.edu&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><BR><BR>On Wed, 29 Sep 2004, Fulvio Copex wrote:<BR><BR>&gt; i'm new to this list and to python too.<BR>&gt; I'm using active state python 2.3 on win32,<BR>&gt; my problem is the following:<BR>&gt; I want learn how to execute system command passing parameters.<BR>&gt;<BR>&gt; for example to copy a file I've tried to write this script:<BR>&gt;<BR>&gt; *****************************<BR>&gt; import os<BR>&gt; os.chdir(''myDirectory")<BR>&gt; cmd="copy"<BR>&gt; parameters="file1 file1_backup"<BR>&gt; myCmd = os.popen(cmd,'w')<BR>&gt; myCmd.write(parameters)<BR>&gt; exitCode = myCmd.close()<BR>&gt; if exitCode:<BR>&gt; print '%s failed, this probably says why:\n%s' % (cmd, myCmd)<BR><BR><BR>Hi Fulvio,<BR><BR><BR>There's a syntax problem here:<BR><BR>&gt; os.chdir(''myDirectory")<BR>^^<BR><BR>but you probably have fixed this already. There's a more important<BR>problem in the use of
 os.popen():<BR><BR>&gt; myCmd = os.popen(cmd,'w')<BR>&gt; myCmd.write(parameters)<BR><BR><BR>Your 'copy' command may need to take in the parameters at the same time as<BR>the popen call, as additional "command-line arguments". I'm not sure how<BR>your 'copy' command works, but it may not be listening to standard input.<BR><BR>So you may need to do something like this:<BR><BR>os.popen("%s %s" % (cmd, parameters))<BR><BR>where we construct the command line all at once, and then pass that off to<BR>popen().<BR><BR><BR>That being said, when you're programming in Python, you actually want to<BR>avoid using os.popen() or os.system() if you can help it. *grin*<BR><BR>The reason is because they're really OS-specific: you can't then take the<BR>same program on Windows and expect it to work on a Unix system, at least,<BR>not without a lot of work. It's also fraught with security problems.<BR><BR><BR><BR>There's already a file-copying function in the 'shutil' shell utilities<BR>module in the
 Standard Library:<BR><BR>http://www.python.org/doc/lib/module-shutil.html<BR><BR><BR>So a better way to do file copying is to use shutils.copy().<BR><BR>###<BR>import os<BR>import shutils<BR>os.chdir("myDirectory")<BR>shutils.copy("file1", "file1_backup")<BR>###<BR><BR>Not only is this easier to read, but it should be much more portable<BR>across operating systems.<BR><BR><BR>If you have more questions, please feel free to ask. Good luck!<BR><BR></BLOCKQUOTE><p>
        

        
                <hr size=1><font face="Arial" size="2"><a href="http://it.rd.yahoo.com/mail/taglines/*http://it.seriea.fantasysports.yahoo.com">Scopri <b>Mister Yahoo!</a></b> -  il fantatorneo sul calcio di Yahoo! Sport'</font>