Commandline closed pipe dont stop shell
Hello,
My target is to run a Commandline buildstep ( its a system test ) and to stop this step if a special text appears in the log.
For this I have the following code in the commandline of tc:
#Start the App
$ADB -s $SERIAL shell am start -S -a android.intent.action.MAIN -n %bundleIdentifier%/com.unity3d.player.UnityPlayerNativeActivity
#Check the Log
adb -s $SERIAL logcat %bundleId% -s Unity | tee logfile | /Applications/ReadADBAndCheck.py
echo "DONE"
in the python script I just check for the string:
#!/usr/bin/python
import sys
import fileinput
for line in fileinput.input():
if "SYSTEM_TEST_DONE" in line:
print "FINISH_FOUND!"
fileinput.close()
sys.exit(0)
print line
if I start this in the normal console everything works like expected.
But if I start it in TC the last thing I see is "FINISH_FOUND" and then I see
tee: stdout: Broken pipe
every second - and stays forever
On a normal shell a non existing pipe should stop the script. ( which it does )
But it doesnt work on TC. Is there any setting for this or is this a bug ?
Any Ideas to fix this any other idea to approach the goal is highly appriciated.
Thanks in advance
Friedrich Wessel
Please sign in to leave a comment.
Hi,
I have tried to reproduce this issue, but I could not. I copied the same python script and in command line of TC I replaced adb command with less of big files. And everything works correctly, build just stops after printing "FINISH_FOUND!" and "DONE".
Can you please attach your build log?
Thanks for the quick answer.
As far as I see it only happens with endless stream services like adb logcat.
if I do :
echo "SYSTEM_TEST_FINISH" | Pythonscript
or
cat testFile | Pythonscript everything is running fine ( if testFile contains the search string )
I cannot provide the full Buildlog - because it contains too much specific information. But here is the important part of the Buildlog:
and from there on Broke pipe gets logged forever.
I found a little ( ugly ) workaround for the Problem, but would be nice to know the root cause.
Workaround is to use custom fifos
look like this:
mkfifo myfifo
adb -s $SERIAL logcat %bundleId% > myfifo &
sleep 10
ReadADBAndCheck.py < myfifo
This will solve the broken pipe issue and script will close.
Sorry, for delay.
The only difference between running command from TC and from command line is that TC invoke bash script using java.
I was able to reproduce this issue on one machine but could not on another. So I think that behaviour depends on bash implementation.