0

I'm the Python beginner and I have a task to do. I have to write a function, that opens a program (.bin), execute it so I can see the results. This program requires 2 arguments from command line. I used os.spawnv, but it doesn't work...

#!/usr/bin/python import sys import os def calculate_chi(): if len(sys.argv)>1: pdb_name=sys.argv[1] dat_name=sys.argv[2] crysol='/usr/bin/crysol' os.spawnv(os.P_NOWAIT,crysol,[crysol,pdb_name,dat_name]) def main(): calculate_chi() 

Can you help me?

3
  • When you say "doesn't work", what do you mean? Could you post a traceback? + fix your indentation. Commented Feb 19, 2014 at 11:00
  • there is no traceback... what's wrong with the indentation? Commented Feb 19, 2014 at 11:20
  • yopy has fixed it for you. Commented Feb 19, 2014 at 11:38

3 Answers 3

1

You can use python subprocess module:

import subprocess proc = subprocess.Popen(['/usr/bin/crysol', sys.argv[1], sys.argv[2]], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while proc.poll() is None: out = proc.stdout.readline() #read crystol's output from stdout and stderr print out retunValue = proc.wait() #wait for subprocess to return and get the return value 
Sign up to request clarification or add additional context in comments.

Comments

0

Use subprocess. It was intended to replace spawn.

import subprocess subprocess.call([crysol, pdb_name, dat_name]) 

12 Comments

I've tried to use this, but nothing happens... in the command line I write: $ python calculate_chi.py saxs.pdb saxs_sam_curve.dat
Nothing happens? Could you explain?
Do you get the desired output when you directly run '/usr/bin/crysol saxs.pdb saxs_sam_curve.dat' from a terminal?
What is your expected output?
@AirelleJab: that's not a sign for "the program doesn't run".
|
0

Everyone uses subprocess.Popen these days. An example call to your process would be

process = Popen(["/usr/bin/crysol", pdb_name, dat_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.