我正在尝试为文件夹集合中的每个实例运行客户端和服务器。我试过这个命令:
$ find ./ -name "Makefile" -execdir xterm -title "Server" -e "timeout -s sigint 8s ./server > serverLog.txt" \; -execdir xterm -title "Client" -e "timeout -s sigint 5s ./client > client1Log.txt" \;
但是这会在xterm窗口中运行服务器8秒钟,然后关闭该窗口并在xterm窗口中运行客户端5秒钟。我需要客户端和服务器同时为每个发现的Makefile运行。
答案 0 :(得分:0)
要同时运行两个命令,您必须使用ambersand &
,它将首次执行发送到后台并继续下一个。所以你必须执行类似
cmd1 & cmd2 &
或cmd1 & cmd2
,取决于您的需求。
接下来,您必须在-execdir
内部转义ambersand,它接受一个命令。一种方法是
find [params] -execdir sh -c 'cmd1 & cmd2' \;
示例:
find [params] -execdir sh -c 'xterm -e "sleep 8" & xterm -e "sleep 5"' \;