2013-12-19 143 views
0

我试图从gnuplot内部执行一些命令,但出现错误。 据我了解我应该使用“!”在命令之前。 这是我的脚本:无法从gnuplot执行shell命令

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 

我在做什么错? 谢谢你的时间!

+0

如果您显示错误,它将有所帮助。我不知道你在这里实际尝试的是什么,似乎比需要复杂得多。 – Bernhard

回答

1

对于每个!都会生成一个新的shell,因此在第二个调用中变量$OUT不可用。您还可以将所有动态进行绘制,如下所示:

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" 
+0

在这种情况下,我没有逃脱$,所以命令完全没用。 – somerandomusername

+0

如果你逃避'$'它的作品?会让我感到惊讶。 – Christoph

+0

我完全重新编写了这段代码的结构,在不同的进程中将数据写入adbmon.log。但是谢谢你的帮助,下次我使用gnuplot的时候会记住 – somerandomusername