【发布时间】:2021-12-31 16:01:35
【问题描述】:
这是我的生成文件:
start:
emulator -avd Galaxy_Nexus_API_28 -writable-system &
charles &
remount:
adb -s emulator-5554 wait-for-device root
adb -s emulator-5554 wait-for-device shell mount -o rw,remount /
adb -s emulator-5554 wait-for-device shell mount -o rw,remount /sys
stop:
kill -9 $(ps -A | grep qemu-system-x86 | awk '{print $1}') &
kill -9 $(ps -A | grep charles.jar | awk '{print $1}') &
test:
ps -A | grep qemu-system-x86
启动 android AVD 和 Charles 工作正常。然后当我运行make stop --just-print 时,我得到这个输出:
kill -9 &
kill -9 &
我猜这意味着$(ps -A | grep qemu-system-x86 | awk '{print $1}') 的输出为空。这很奇怪,原因有两个:
首先,因为当我运行 make test 时,我得到以下(正确)输出:
ps -A | grep qemu-system-x86
64434 pts/0 00:00:59 qemu-system-x86
其次,因为在终端中运行 echo $(ps -A | grep qemu-system-x86 | awk '{print $1}') 可以很好地打印出正确的进程 pid。所以ps | grep 命令在 makefile 中有效,但 awk 打印添加仅在终端中有效。怎么会这样?我该如何解决?
现在我将坚持在调用make stop 时使用killall -9 java,但这当然不是最好的处理方式。
【问题讨论】:
-
没有答案,但您可以将:
$(ps -A | grep charles.jar | awk '{print $1}')更改为:$(ps -A | awk '/charles.jar/{print $1}') -
嗨,谢谢,没错:)。你可能已经猜到了,我是 grep 和 makefile 的新手。
-
我对 makefile 唯一了解的是,它在输入 make ... 时会被读取... ????
-
你需要使用
$$而不是$来防止make解释$(ps -A | grep qemu-system-x86 | awk '{print $1}')。 -
这能回答你的问题吗? Four Dollar signs in Makefile