Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Run a external program.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Yasser Almeida Hernández  
View profile  
 More options Nov 14, 2:26 pm
Newsgroups: comp.lang.python
From: Yasser Almeida Hernández <pedro...@fenhi.uh.cu>
Date: Sat, 14 Nov 2009 14:26:11 -0500
Local: Sat, Nov 14 2009 2:26 pm
Subject: Run a external program.
Hi all!!

I'm writing a script where i call a external program which receive  
some arguments.
One of this arguments is stored in a variable, that is passed as  
argument as well:

import os
...
f = open(file1, 'r')
s = 'command $f -i file2 -w 1.4 -o file3.out'
os.system(s)
...

When i run the script i get the next message...
'-i: No such file or directory'
... with a obvious error in the exit of the program. If i remove the  
option -i i get the same error with every option, even with those who  
don't get any file as argument. (file2 exist).
BUT, when i run the external program in a python shell, it works...

What's wrong?

Please help me...
Thanks

--
Lic. Yasser Almeida Hernández
Center of Molecular Inmunology (CIM)
Nanobiology Group
P.O.Box 16040, Havana, Cuba
Phone: (537) 271-7933, ext. 221

----------------------------------------------------------------
Correo FENHI


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Nov 14, 2:53 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Sat, 14 Nov 2009 19:53:50 +0000
Local: Sat, Nov 14 2009 2:53 pm
Subject: Re: Run a external program.

The name 'f' in the Python script exists only in Python and is unrelated
to the '$f' that the shell sees.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Tolonen  
View profile  
 More options Nov 14, 3:03 pm
Newsgroups: comp.lang.python
From: "Mark Tolonen" <metolone+gm...@gmail.com>
Date: Sat, 14 Nov 2009 12:03:23 -0800
Local: Sat, Nov 14 2009 3:03 pm
Subject: Re: Run a external program.

"Yasser Almeida Hernández" <pedro...@fenhi.uh.cu> wrote in message
news:20091114142611.sj45qput2c84s0w0@correo.fenhi.uh.cu...

Please post a small, complete example of your code and the error message.
Cut-and-paste them exactly.  Also provide the shell command you are running
that works.

-Mark


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yasser Almeida Hernández  
View profile  
 More options Nov 14, 3:07 pm
Newsgroups: comp.lang.python
From: Yasser Almeida Hernández <pedro...@fenhi.uh.cu>
Date: Sat, 14 Nov 2009 15:07:26 -0500
Local: Sat, Nov 14 2009 3:07 pm
Subject: Re: Run a external program.
So, how can i pass an argument as a variable in this context...?

Quoting MRAB <pyt...@mrabarnett.plus.com>:

--
Lic. Yasser Almeida Hernández
Center of Molecular Inmunology (CIM)
Nanobiology Group
P.O.Box 16040, Havana, Cuba
Phone: (537) 271-7933, ext. 221

----------------------------------------------------------------
Correo FENHI


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Rebert  
View profile  
 More options Nov 14, 3:50 pm
Newsgroups: comp.lang.python
From: Chris Rebert <c...@rebertia.com>
Date: Sat, 14 Nov 2009 12:50:14 -0800
Local: Sat, Nov 14 2009 3:50 pm
Subject: Re: Run a external program.

2009/11/14 Yasser Almeida Hernández <pedro...@fenhi.uh.cu>:

> So, how can i pass an argument as a variable in this context...?

Use the string variable's value when specifying the arguments to the command.

Here's how you'd do it using the newer `subprocess` module:

import sys
import subprocess
args = ['command', file1, '-i', 'file2', '-w', '1.4', '-o',
'file3.out'] #assuming only file1 is variable
return_code = subprocess.call(args, stdin=sys.stdin,
stdout=sys.stdout, stderr=sys.stderr)

Cheers,
Chris
--
http://blog.rebertia.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Nov 14, 3:56 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Sat, 14 Nov 2009 20:56:30 +0000
Local: Sat, Nov 14 2009 3:56 pm
Subject: Re: Run a external program.
Yasser Almeida Hernández wrote:
> So, how can i pass an argument as a variable in this context...?

You can't pass arbitrary values on a command line. In this case, why not
just pass the path of the file?

s = 'command "%s" -i file2 -w 1.4 -o file3.out' % file1


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yasser Almeida Hernández  
View profile  
 More options Nov 14, 4:23 pm
Newsgroups: comp.lang.python
From: Yasser Almeida Hernández <pedro...@fenhi.uh.cu>
Date: Sat, 14 Nov 2009 16:23:22 -0500
Local: Sat, Nov 14 2009 4:23 pm
Subject: Re: Run a external program.
All ran ok!!

Thanks a lot

Quoting MRAB <pyt...@mrabarnett.plus.com>:

--
Lic. Yasser Almeida Hernández
Center of Molecular Inmunology (CIM)
Nanobiology Group
P.O.Box 16040, Havana, Cuba
Phone: (537) 271-7933, ext. 221

----------------------------------------------------------------
Correo FENHI


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Terry Reedy  
View profile  
 More options Nov 14, 8:14 pm
Newsgroups: comp.lang.python
From: Terry Reedy <tjre...@udel.edu>
Date: Sat, 14 Nov 2009 20:14:23 -0500
Local: Sat, Nov 14 2009 8:14 pm
Subject: Re: Run a external program.
Top-posting makes things more confusing. You cannot pass a Python file
object to an external process. Pass the name instead.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google