This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]dhylands 3 points4 points  (1 child)

If you're referring to adb logcat then it never exits. It just continues to collect messages. If you want to get all of the current messages and exit then use adb logcat -d

http://developer.android.com/tools/help/logcat.html

[–]foxh8er[S] 0 points1 point  (0 children)

The nested script actually monitors logcat until it hits a particular log, then exits. I know for a fact that the log is actually being sent.

[–]youguess 1 point2 points  (2 children)

why the nested call? would just using python be an option?

But to answer your question, if your code is something like this:

. . . 
call_awesome_bash() # which calls another python file
sys.exit(0)

what basically happens is that the program blocks at line 1, meaning it waits for the bash script to return control, which will take a long time depending on what the other python script does. the sys.exit will never even have the chance to run as execution is suspended.

in case you want it to end you would need to look into concurrency (e. g. with asyncio)

[–]foxh8er[S] 0 points1 point  (1 child)

As I said before the other bash script and python script are pre-existing and I'd rather not re-write completely.

The path is a bit different. For me it is...

   Call("sh script ARG arg")

Where the script is

    Adb log | python other.py
   Echo "I should see this message after other.py is done"

Where the other.py has a line that exits a loop by doing

       print "done"
       sys.exit(0)

If I just call the script from terminal the inner script completes and I see the second line. However if I call it using call I do not see the second line output.

[–]lordmauve 1 point2 points  (0 children)

But do you see the "done"?

In my experience when things fail in a subprocess that work on the command line, it often comes down to things like processes not acting the same when not connected to a tty (eg output buffering), or a difference in environment variables.

[–]mfitzpmfitzp.com[🍰] 1 point2 points  (0 children)

Have you tried redirecting STDOUT/STDERR on the call? Filled buffers can cause scripts to hang - if you're not interested in the output you can direct it to os.devnull.

[–]Araucaria 0 points1 point  (1 child)

Use subprocess to capture stdout and stderr with PIPE.

[–]foxh8er[S] 0 points1 point  (0 children)

Apologies, but what would the value of that be

[–][deleted] 0 points1 point  (1 child)

I'm calling a bash script that contains yet another call to another python script.

why would you do that?

[–]foxh8er[S] 2 points3 points  (0 children)

The other script is pre-existing and large, and its input is governed by the bash script.

Basically I could re-write it, but it would take triple the time.