0

The question has been asked elsewhere, but I do not see any solutions for this...

I have a Python script that contains subprocess calls of the form:

source_density = subprocess.check_output(["adb", device_dhm1, "-P8080", "-s", source, "shell", "wm density | head -2 | tail -1"])

When running this script through cmd, everything runs fine. However now I am trying to run it through Jenkins and I am getting the following error output:

======================================================================
ERROR: test_sanity (__main__.ABC)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/user123/.jenkins/workspace/Test/Jenkins-Source-Sanity.py", line 145, in test_sanity
    source_density = subprocess.check_output(["adb", device_dhm1, "-P8080", "-s", source, "shell", "wm density | head -2 | tail -1"])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 216, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
5
  • The error message suggests your program cannot locate the executable file adb. You can check the PATH environment variable. Commented Jan 10, 2020 at 18:09
  • but I am wondering why I don't see this when running via terminal? Commented Jan 10, 2020 at 18:11
  • 1
    Looks like it cannot find adb command in PATH, maybe you can try giving full path like /usr/bin/adb Commented Jan 10, 2020 at 18:12
  • 1
    You have to set shell=True in the call of check_output Commented Jan 10, 2020 at 18:12
  • 1
    @RishabhArya Thank you! giving the full path to adb worked perfectly! Commented Jan 10, 2020 at 18:17

1 Answer 1

1

Per default, check_output treats the first argument as a single executable instead of a shell command (cmd command). So you have to set the flag shell=True explicitly.

source_density = subprocess.check_output(["adb", device_dhm1, "-P8080", "-s", source, "shell", "wm density | head -2 | tail -1"], shell=True)

Please read the doc here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.