Linux 在不让我等待的情况下运行命令

Linux 在不让我等待的情况下运行命令,linux,shell,terminal,sh,calabash,Linux,Shell,Terminal,Sh,Calabash,我是Shell脚本Linux的新手。 我正在使用Android进行自动化测试,所以我想运行一些shell脚本,如下所示: 由adb启动记录屏幕(cmd1.sh) 执行场景测试,然后停止/保存记录文件(cmd2.sh) 不幸的是,在运行cmd1.sh时,我必须等待3分钟才能运行cmd2.sh。 这意味着我无法录制视频:悲伤: 以下是“我的运行”命令的内容: run.sh文件内容: ./cmd1.sh & # run this command in the backgrou

我是Shell脚本Linux的新手。
我正在使用Android进行自动化测试,所以我想运行一些shell脚本,如下所示:

  • 由adb启动记录屏幕(cmd1.sh)
  • 执行场景测试,然后停止/保存记录文件(cmd2.sh)
  • 不幸的是,在运行cmd1.sh时,我必须等待3分钟才能运行cmd2.sh。
    这意味着我无法录制视频:悲伤:
    以下是“我的运行”命令的内容:

    run.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh$
    ./cmd2.sh

    cmd1.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    adb外壳屏幕记录/sdcard/file.mp4

    cmd2.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    葫芦android运行app.apk

    最后,我打开终端,然后运行命令:

    //run.sh

    当然,视频无法保存,因为cmd1.sh完成后,cmd2.sh将运行
    在这一点上有人能帮我吗?
    非常感谢你

    @Jrican已更新
    以下是我可以播放视频录制的手动步骤。
    1.打开终端A
    2.运行命令1(开始录制屏幕脚本)
    3.打开其他终端B,然后运行命令2
    4.命令2完成后,返回终端A,然后按Ctrl键C。
    5.确认/sdcard/file.mp4中的视频可以正常播放


    我正在使用MAC OSX Yosemite 10.10.5同时运行两个命令,然后在完成第二个命令后终止第一个命令的PID:

    #!/bin/sh
    
    # Run first command in background:
    ./cmd1.sh & PID="$!"
    
    # Run second command:
    ./cmd2.sh
    
    # Kill the first command:
    kill "$PID"
    

    要同时运行两个命令,然后在完成第二个命令后终止第一个命令的PID:

    #!/bin/sh
    
    # Run first command in background:
    ./cmd1.sh & PID="$!"
    
    # Run second command:
    ./cmd2.sh
    
    # Kill the first command:
    kill "$PID"
    
    简易解决方案: run.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    更正确的解决方案: run.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    简易解决方案: run.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    
    更正确的解决方案: run.sh文件内容:

    ./cmd1.sh &          # run this command in the background
    ./cmd2.sh            # run this command to completion 
    kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)
    
    ./cmd1.sh &            # run this command in the background
    recPID=$!              # save the PID for this process for later
    ./cmd2.sh              # run this command to completion 
    kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)
    


    这行吗?$/cmd1.sh和/cmd2.sh谢谢!让我试试,然后尽快更新你@我试过了。但仍然不起作用。错误:$:未找到命令不要将$符号放在前面,这只是为了表示命令提示符../cmd1.sh&/cmd2.sh这行吗?$/cmd1.sh&/cmd2.sh谢谢!让我试试,然后尽快更新你@我试过了。但仍然不起作用。错误:$:command not found不要将$符号放在前面,这只是表示命令提示符../cmd1.sh&/cmd2.shI不想在这里等待。cmd1意味着开始录制。cmd2意味着做测试用例。最重要的是,我想录制一段视频。希望你能解决我的问题我消除了时间延迟。虽然我觉得这仍然不能解决你的问题。我将尝试在我的android上安装这些软件包,看看是否可以复制这个用例。谢谢。Jrican的回答是正确的。但是我还有一个问题,我想在Cmd 2完成???编辑后终止/停止Cmd1,以便在第二个进程完成后终止第一个进程。我已经尝试了您的命令。我的视频仍然无法运行。我怎样才能确认我已经杀了你?因为如果我通过CTR C停止命令1,我可以正常播放视频。我想问题是因为无法在保存文件之前杀死cmd1我不想在这里等待。cmd1意味着开始录制。cmd2意味着做测试用例。最重要的是,我想录制一段视频。希望你能解决我的问题我消除了时间延迟。虽然我觉得这仍然不能解决你的问题。我将尝试在我的android上安装这些软件包,看看是否可以复制这个用例。谢谢。Jrican的回答是正确的。但是我还有一个问题,我想在Cmd 2完成???编辑后终止/停止Cmd1,以便在第二个进程完成后终止第一个进程。我已经尝试了您的命令。我的视频仍然无法运行。我怎样才能确认我已经杀了你?因为如果我通过CTR C停止命令1,我可以正常播放视频。我认为问题来自于无法在保存文件之前杀死cmd1。我正在确认为什么保存后无法播放视频。我将以另一种方式更新上述视频播放。我正在确认为什么保存后无法播放视频。我会用另一种方式来更新上面提到的视频。