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

Error when building on windows #106

Closed
SakiiR opened this issue May 27, 2019 · 3 comments
Closed

Error when building on windows #106

SakiiR opened this issue May 27, 2019 · 3 comments

Comments

@SakiiR
Copy link

SakiiR commented May 27, 2019

When building my ssh server on windows ... I get those errors:

./make.sh                         (*master+13) 15:29:46
[~] Compiling 
#
internal/pkg/ssh/ssh.go:17:17: not enough arguments in call to syscall.Syscall
internal/pkg/ssh/ssh.go:17:18: undefined: syscall.SYS_IOCTL
internal/pkg/ssh/ssh.go:17:53: undefined: syscall.TIOCSWINSZ
internal/pkg/ssh/ssh.go:36:13: undefined: pty.Start
An error has occurred! Aborting the script execution...

I guess this is because I am using pty and stuff in my handler ...

func giveShell(s ssh.Session) {
	cmd := exec.Command(getOSCommand())
	ptyReq, winCh, isPty := s.Pty()
	if isPty {
		cmd.Env = append(cmd.Env, fmt.Sprintf("TERM=%s", ptyReq.Term))
		f, err := pty.Start(cmd)
		if err != nil {
			panic(err)
		}
		go func() {
			for win := range winCh {
				setWinsize(f, win.Width, win.Height)
			}
		}()
		go func() {
			io.Copy(f, s) // stdin
		}()
		io.Copy(s, f) // stdout
	} else {
		io.WriteString(s, "No PTY requested.\n")
		s.Exit(1)
	}
}

Is there any way to do cross platform command execution ?

@SakiiR
Copy link
Author

SakiiR commented May 27, 2019

I found a way to do it without PTY ...

func giveShell(s ssh.Session) {

	strCommand := getOSCommand()

	cmd := exec.Command(strCommand[0], strCommand[1:]...)
	cmd.Stderr = s
	cmd.Stdout = s
	cmd.Stdin = s

	cmd.Start()
	cmd.Wait()
}

@belak
Copy link
Collaborator

belak commented Jun 12, 2019

I don't believe this is an issue with our code - the pty functions we provide are really a thin wrapper and don't actually call out to a pty library. As an example, we don't even use TIOCSWINSZ or the other syscalls mentioned in our code (aside from in an example). You pay need to find a different way of handling ptys if your code needs to work on Windows.

Generally, when you're trying to build something in a cross platform way, you will have to avoid the syscall package as they are very platform specific.

@belak belak closed this as completed Jun 12, 2019
@JustinTimperio
Copy link

@SakiiR Did you ever find a solution here? If not hopefully creack/pty#109 may provide some limited Windows support.

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

3 participants