Skip to content

Error when building on windows #106

Closed

Description

@SakiiR

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 ?

Activity

  1. SakiiR commented on May 27, 2019

    @SakiiR
    Author

    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()
    }
  2. belak commented on Jun 12, 2019

    @belak
    Collaborator

    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.

  3. JustinTimperio commented on Apr 5, 2021

    @JustinTimperio

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions