Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Process.launchedProcess()与Ruby system()的行为_Swift_Shell_Scripting - Fatal编程技术网

Swift Process.launchedProcess()与Ruby system()的行为

Swift Process.launchedProcess()与Ruby system()的行为,swift,shell,scripting,Swift,Shell,Scripting,我正在尝试将一些Ruby代码转换为Swift。Ruby代码使用 system ... 我成功地在Swift中获得了与流程API几乎相同的行为: Process .launchedProcess(launchPath: ..., arguments: ...) .waitUntilExit() 但是,有两个区别: 当启动的程序尝试进行分页时,Swift版本挂起(因此启动“git--no pager diff…”有效,“git diff…”挂起,如果diff足够长) 如果在启动的程序运行

我正在尝试将一些Ruby代码转换为Swift。Ruby代码使用

system ...
我成功地在Swift中获得了与流程API几乎相同的行为:

Process
  .launchedProcess(launchPath: ..., arguments: ...)
  .waitUntilExit()
但是,有两个区别:

  • 当启动的程序尝试进行分页时,Swift版本挂起(因此启动“git--no pager diff…”有效,“git diff…”挂起,如果diff足够长)
  • 如果在启动的程序运行时我命令cmd+c中断,我的Swift脚本将退出,但启动的程序将继续运行。在Ruby版本中,两者都被中断
  • 我如何避免这些问题

    更新:通过在脚本收到中断信号时手动终止任何启动的进程,解决了问题2:

    var globalCommand: Process? = nil // May be set later
    
    signal(SIGINT) { _ in
      globalCommand?.interrupt()
      exit(0)
    }