Skip to content

Instantly share code, notes, and snippets.

@BoQsc
Last active July 17, 2019 16:41
Show Gist options
  • Save BoQsc/048ea14bbb1f9555ba058027aa22ff3a to your computer and use it in GitHub Desktop.
Save BoQsc/048ea14bbb1f9555ba058027aa22ff3a to your computer and use it in GitHub Desktop.
Launches Firefox in Headless mode, as background process and waits for output from Firefox. Also saves the PID of the launched Firefox to a variable.
#!/bin/bash
killall "firefox";
exec 3< <(firefox --headless 2>&1 & echo $!) # & firefox_pid=$!
#echo $firefox_pid &!
for i in 1 2 3 4 5; do read <&3 line;
if [ $i -eq 1 ]; then firefox_pid="$line"
fi
if [ "$line" == "*** You are running in headless mode." ]; then echo "here is the line"
fi
echo "$i $line";
done
#tempo=`$(firefox --headless) & `;
#wait
#echo "here &(<$tempo) here"
#firefox_pid=$!
# firefox --headless &
#firefox_pid=$!
# echo $firefox_pid
# for i in 1 2 3; do read <&3 line; echo "$line"; done
#wait
# kill "$firefox_pid"
#echo $output
#kill "$firefox_pid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment