23 lines
587 B
Go
23 lines
587 B
Go
package ssh
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// Exec replaces the current process with the native ssh client via syscall.Exec.
|
|
// All existing SSH configs, keys, and agent forwarding remain intact.
|
|
func Exec(args []string) error { return SSH.Exec(args) }
|
|
|
|
// Exec replaces the current process with the client's binary.
|
|
func (c Client) Exec(args []string) error {
|
|
path, err := exec.LookPath(c.Name)
|
|
if err != nil {
|
|
return fmt.Errorf("%s not found in PATH: %w", c.Name, err)
|
|
}
|
|
argv := append([]string{c.Name}, args...)
|
|
return syscall.Exec(path, argv, os.Environ())
|
|
}
|