Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute output #44

Open
blackndoor opened this issue Jun 3, 2022 · 1 comment
Open

execute output #44

blackndoor opened this issue Jun 3, 2022 · 1 comment

Comments

@blackndoor
Copy link

How can we get the output result of a command ?

I created a swift file with the following content:

import Foundation
import SwiftSH

class sshShell {
    func executeCMD(cmd:String) -> String {
        let command = Command(host: "192.168.1.50", port: 22)
        var output:String = ""
    
        command!.connect()
               .authenticate(.byPassword(username: "user1", password: "password1"))
               .execute(cmd) { (cmd, result: String?, error) in
                   if let result = result {
                       print("here")
                       print(result)
                       output = result
                   } else {
                       print("there")
                       output =  "ERROR"
                   }
               }
        return output
    }
}

And in the ContentView, I have:

        var output: String = ""
        Button(action: {
            let atest = sshShell()
            output = atest.executeCMD(cmd: "/bin/ls -la")
        }, label: {
            Text("Click me")
        })

        Text(output)
            .padding()

Here is the debugger output:

DEBUG: Timeout set to 10.0 seconds
INFO: Libssh2 v1.9.0
DEBUG: 192.168.1.50 resolved. 1 addresses
INFO: Connection to 192.168.1.50 on port 22 successful
DEBUG: Remote banner is SSH-2.0-OpenSSH_8.6
DEBUG: Fingerprint is BF:...
DEBUG: Supported authentication methods: [Public Key, Password, Keyboard Interactive]
DEBUG: Authenticating by Password
DEBUG: Opening the channel...
DEBUG: Environment: []
INFO: Bye bye
DEBUG: Disconnected

The connection seems OK but no result.

@Elektronenhirn108
Copy link

Have you found a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants