Jivan
Jivan

Reputation: 23068

Subprocess returns after a couple seconds with no error, but command didn't do its job

There is a subprocess.run() command I'm using (1):

    p = subprocess.run([
        '/home/ubuntu/my_script.sh',
        'my_arg_1',
        'my_arg_2'
    ])

If I run the above, the process returns after about 2 seconds (way too short) and doesn't produce the handful of files it's supposed to (nothing is created, as if the program didn't run at all). There is no apparent error or exception.

Now if I run the following from a shell (2):

$ /home/ubuntu/my_script.sh my_arg_1 my_arg_2

The program runs for about 15 seconds (as expected) and generates the expected files.

I double and tripled-check that the linux command used in (2) and the concatenation of the arguments in (1) are rigorously and precisely the same. Still, no effet.

Am I missing something? Could there be user permission issues? How comes subprocess.run() returns after a couple of seconds and not immediately, if it's not running the target command?

EDIT:

The actual command is as follows:

/home/ubuntu/DataScience/alphapose_dress.sh /home/ubuntu/dresses/whole-dresses/VahT2ei1no.jpg /home/ubuntu/dresses/alphapose_results

So no, it's not related to relative paths issues

EDIT2:

The following:

cmd = [
    config.alphapose_script,
    img_path,
    config.alphapose_outdir
]

with Popen(cmd, stdout=PIPE, bufsize=1, universal_newlines=True) as p:
    for line in p.stdout:
        print(line, end='')

... prints or outputs absolutely nothing. Whereas the actual command when run from a shell outputs many lines.

Upvotes: 2

Views: 500

Answers (1)

ABDULVAHAB Kharadi
ABDULVAHAB Kharadi

Reputation: 54

Try this:

from subprocess import run,PIPE p = run([ '/home/ubuntu/my_script.sh', 'my_arg_1', 'my_arg_2' ], stdout=PIPE, stderr=PIPE) print(p.stderr)

It will printout the error.

Upvotes: 3

Related Questions