0

I have the following script that attempts to submit a job to the PBS queue.

import sys
import os
import subprocess

inpfile="sim.input"
qscript="run.sh"

#2.1 create a directory to launch the script from
dir="test"
os.system("mkdir {}".format(dir))
os.system("cp {} {} {}".format(qscript,inpfile,dir))


#2.2 launch the simulation
subprocess.Popen(["qsub",qscript],cwd=dir)

The script works, but after I hit Enter, I get in the terminal an empty line, so I have to hit Enter again to recover my prompt. This doesn't happen if I do subprocess.call(). So, the question is how to get rid of that newline? The following is what I see in the terminal:

dude@machine$ python submit01.py 
dude@machine$ 3463.machine.com

dude@machine$ 

Edit: the script run.sh

#!/bin/bash
#PBS -S /bin/bash
#PBS -N job
#PBS -l nodes=1:ppn=1
#PBS -j oe
#PBS -V
cd $PBS_O_WORKDIR
pwd

sim.input can be any file.

user3653831
  • 235
  • 6
  • 19

1 Answers1

1

I think I found my answer here

The empty line for the subprocess.Popen() comes from me not specifying the standard output. If that's not specified, there is an empty line in the terminal which is, as far as I can tell, harmless. So, the code could be:

with open("output.txt","w") as out:
    #2.2 launch the simulation
    subprocess.Popen(["qsub",qscript],cwd=dir,stdout=out)

and will not give an empty line.

Community
  • 1
  • 1
user3653831
  • 235
  • 6
  • 19