Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 运行系统程序与基础缺陷_Swift_Linux_Sublimetext3_Archlinux - Fatal编程技术网

Swift 运行系统程序与基础缺陷

Swift 运行系统程序与基础缺陷,swift,linux,sublimetext3,archlinux,Swift,Linux,Sublimetext3,Archlinux,尝试使用swift脚本在系统中运行可执行文件。我回答了第二个答案,但是我犯了一个错误,抱怨基金会没有正确地建立: 错误: /usr/lib/swift/CoreFoundation/CoreFoundation.h:25:10: note: while building module 'SwiftGlibc' imported from /usr/lib/swift/CoreFoundation/CoreFoundation.h:25: #include <sys/types.h>

尝试使用swift脚本在系统中运行可执行文件。我回答了第二个答案,但是我犯了一个错误,抱怨基金会没有正确地建立:

错误:

/usr/lib/swift/CoreFoundation/CoreFoundation.h:25:10: note: while building module 'SwiftGlibc' imported from /usr/lib/swift/CoreFoundation/CoreFoundation.h:25:
#include <sys/types.h>
         ^
我在Linux(Archlinux)中使用Sublime REPL运行此程序。问题:

    我所做的其他小项目都很好,没有发现基础上的错误,因为它在这里抱怨。我的安装有问题吗

  • 使用Glibc运行可执行文件有没有更简单的方法


    • 回答我自己的问题。这似乎是swift的Sublime REPL中的一个bug,因为在命令行中运行它可以使代码顺利运行。另外,没有更新到Swift 3的代码也有一些问题,下面是传递的代码。我仍然希望找到一种使用Glibc在Swift中运行可执行文件的方法

      #! /usr/bin/swift
      
      import Foundation
      
      func execCommand(command: String, args: [String]) -> String {
          if !command.hasPrefix("/") {
              let commandFull = execCommand(command: "/usr/bin/which", args: [command]).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
              return execCommand(command: commandFull, args: args)
          } else {
              let proc = Process()
              proc.launchPath = command
              proc.arguments = args
              let pipe = Pipe()
              proc.standardOutput = pipe
              proc.launch()
              let data = pipe.fileHandleForReading.readDataToEndOfFile()
              return String(data: data, encoding: String.Encoding.utf8)!
          }
      }
      
      let commandOutput = execCommand(command:"/bin/echo", args:["Hello, I am here!"])
      print("Command output: \(commandOutput)")
      
      #! /usr/bin/swift
      
      import Foundation
      
      func execCommand(command: String, args: [String]) -> String {
          if !command.hasPrefix("/") {
              let commandFull = execCommand(command: "/usr/bin/which", args: [command]).trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
              return execCommand(command: commandFull, args: args)
          } else {
              let proc = Process()
              proc.launchPath = command
              proc.arguments = args
              let pipe = Pipe()
              proc.standardOutput = pipe
              proc.launch()
              let data = pipe.fileHandleForReading.readDataToEndOfFile()
              return String(data: data, encoding: String.Encoding.utf8)!
          }
      }
      
      let commandOutput = execCommand(command:"/bin/echo", args:["Hello, I am here!"])
      print("Command output: \(commandOutput)")