From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 4AF333857C4F for ; Thu, 26 Nov 2020 15:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4AF333857C4F Received: by mail-ot1-x331.google.com with SMTP id n12so2175779otk.0 for ; Thu, 26 Nov 2020 07:18:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=tvaulf6NeZJdTl9zLZfQ4dKy/CIwDUoIRjhqWk87nQI=; b=BDfPlFtgyueuiiq9GZYvq9Gt1f2TGMFNqeom5QE5nhMjhhRLcVkqyYNnnOOWowUJa9 37juzTzYy12B1+KzSgQTUI/uv7GCmOquJxvpnVdt36Oztc+3Mbg9Kr0DuxjodV8L0/51 dbYPSu9zwNgqjBL0b7Y592R0VK4ur6H/JYKK9NE/fbvN8nsxYus2fTCczq5wIy0S37cw jQaJqck/cMz5YojrtfblC/zFtQGOjiADFxpeh8jVBJiqRniIRb2pvsR/euBQg8Qccqk8 doKSOxcbEnS5blIRHVKd2tBExtmMNn5e00XGYaqEH07vQGIMtTnIFVp91UKCSmMdOKx8 RyJw== X-Gm-Message-State: AOAM532nY29o5ySiFGXhjsRKxN56GZH/F3fSJHc+F2qGXnpjbjhzAEt3 NWTjiOR9ECSX0A6cTLkE5PPfzgXwj+blD+Ruo+B8qK2/9wnKNg== X-Google-Smtp-Source: ABdhPJxxI80deajlqh5NtJe49rXmbPIH4bmVcqQ6h8MG49bpqYVpPv1akPm1oQg8AuuwqAvPHMydJdG8JLU7xc36n9I= X-Received: by 2002:a05:6830:1dab:: with SMTP id z11mr2587287oti.247.1606403928428; Thu, 26 Nov 2020 07:18:48 -0800 (PST) MIME-Version: 1.0 From: Oleksandr Gavenko Date: Thu, 26 Nov 2020 17:18:37 +0200 Message-ID: Subject: Help with setting Cygwin's Emacs W32 TRAMP to WSL 1 To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Nov 2020 15:18:50 -0000 I'm using Cygwin for two reasons: mintty + Emacs w32. Nowadays WSL 1 has become important (vendors provide ready to work .deb packages, I use: Ansible + Google Cloud SDK, if name any). Still WSL 1 lacks UI and integrates less smoothly into my workflow to replace Cygwin's amazing Emacs W32. WSL1 files are "hidden" for regular access. Emacs has TRAMP mode to access foreign environments: https://www.gnu.org/software/tramp/ I tried to define configuration that should have allowed to access WSL 1 from Cygwin's Emacs via "wsl sh" jump (the way TRAMP support "su" & "sudo" jumps): * https://www.reddit.com/r/emacs/comments/jrkgmy/tramp_for_wsl_1_from_cygwin_emacsw32/ * https://github.com/microsoft/WSL/issues/6236 - wsl.exe periodically sends control characters making impossible "piping" via interactive/terminal mode The problem is that when Cygwin's Emacs invokes "wsl.exe" conhost or wsl?? thinks it is in a PTY mode and sends different "clearing" terminal escape sequences (see WSL issue report). I reproduce garbage with Elisp code: (setq xxx (make-process :name "xxx" :buffer "xxx" :command '("wsl" "echo" "OK") :connection-type 'pty)) (stop-process xxx) Note that changing the last argument "pty" => "pipe" solves the problem, but things are a bit complicated... TRAMP mode has been implemented via call to "sh" by internal API "make-process". And then TRAMP sends "wsl ..." to the shell so WSL thinks it is in PTY and I have no way to influence that decision (( I tried stupid tricks like passing everything related to "ws.exe" via pipe to "cat": (with-eval-after-load 'tramp (setf (alist-get "wsl" tramp-methods nil nil #'equal) '((tramp-login-program "sh") (tramp-login-args (("-c") ("wsl") ("-u" "%u") ("-d" "%h") ("|" "cat"))) (tramp-remote-shell "/bin/sh") (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-c")) (tramp-connection-timeout 10) (tramp-session-timeout 300)))) or define a wrapper script that has "wsl ... | cat" inside. Nothing helped. Few experiments with Cygwin's Expect also failed as I forgot everything about that obscure tech... So I need to write some wrapper that will bidirectionally pipe to "wsl.exe" putting wsl into piped instead TTY mode. It can be that there is a ready solution. If not please advise which API should I use to write such a wrapper. Should it be Cygwin's pipe/dup2/fork/execvp or popen? Or should it be Windows native CreateChildProcess / WriteToPipe / ReadFromPipe as here: https://docs.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output Please CC me in replies, I'll check the mail archive after a week to not lose any responses.