i got the output ok print(contents) but i dont know how to include that variable in the command
task.arguments = ["-c", "./file/sshpass -p **contents** ssh -o StrictHostKeyChecking=no root@149.28.28.xxx"]
Looking forward to your guidance
my command:
import Foundation
if let url = URL(string: "http://www.example.vn/test.txt") {
do {
let contents = try String(contentsOf: url)
print(contents)
} catch {
// contents could not be loaded
}
@discardableResult func shell(_ command: String) -> String {
let task = Process()
task.launchPath = "/bin/bash"
task.arguments = ["-c", "./file/sshpass -p +contents+ ssh -o StrictHostKeyChecking=no root@149.28.28.xxx"]
task.arguments = ["-c", "./file/sshpass -p +contents+ scp ./Lockdown/*.zip root@149.28.28.xxx:/var/www/html/xxx/"]
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
return output
}
// Example usage:
let t = shell("ls")
print("\(t)")
}