简体   繁体   中英

Can't execute shell commands from gnuplot

I'm trying to execute some commands from inside gnuplot, but I'm getting error. As far as I understand I should use "!" before command. Here is my script:

echo "
set terminal dumb 
!OUT=$(adb shell dumpsys meminfo $PID | grep TOTAL )
!OUT=$(echo $OUT | sed -r 's/ +/ /g' | cut -d ' ' -f 2-)
!echo $OUT >> adbmon.log
plot  'adbmon.log' using 1:6 title 'Free'
" > sample.gp && gnuplot sample.gp

What am I doing wrong? Thank you for your time!

For every ! a new shell is spawned, so that the variable $OUT is not available in the second call. You can also plot everything on-the-fly as follows:

gnuplot -persist -e "set terminal dumb; plot '< adb shell dumpsys meminfo $PID | grep TOTAL | sed -r ''s/ +/ /g'' | cut -d '' '' -f 2-' using 1:6"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM