Running Terminal within a Python Script -


I am trying to run a command in the terminal via a Python script. The command, which only takes three arguments, works perfectly when executed in the terminal. What is entered in the command line here:

  gpmetis input file number offset   

Ask inputfile anywhere, desktop, < Code> outputfile is executed in the same place after gpmetis (it is named as inputfile.part.numberOfSections ). gpmetis works only in the terminal, but for condensing purposes, I want to use it in the middle of the Python script to save time. (I can already alter the files from terminal and python and almost)

But this is where I get problems ... this and it gives a useful signal that how the terminal in Python To be executed, I'm still not getting outputfile when I run Python code It seems that the output is suppressed or the way I call the terminal is faulty.

I am currently saying terminal:

  def terminal (inputfile, numberparts): osystem ("gpmetis inputfile numparts") outputfile = "inputfile.part." + NumParts comes back to outputfile   

And I have not received any error from this, but I have not found any output files What am I missing here and if you know that you can explain it? I am trying to learn dragon, so whatever I want to screw will be greatly appreciated.

os has been imported. In my mistake I am doing "back" outputfile , but I do not see a outputfile on my desktop, which should be dealt with first problem (one One step in time!)

Note: I found that it is related, but will it help me? I'm having trouble understanding this.

First of all, you have os.system < / Code>. A zero-zero return value usually indicates that an error has occurred.

It looks like you are trying to use the parameter in your command, in that case it should look like:

  def terminal (inputfile, numberparts): command = 'GPTIS' + inputfile + '' + str (nampperes) OSSystem (command) outputfile = inputfile + '.part.' + Str (NumParts) Return output file   

Finally, depending on the answer, it seems that you can be better by using the subprocess module You can execute only one command:

  Subprocess subprocess import coal (['gpmetis', inputfile, strip (newpoints)])    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -