2

I posted this on stack (now deleted), but was told that this might be a more appropriate forum.

I'm on windows-subsystem-linux 1 with Ubuntu with the Windows Ubuntu terminal.

Using advice from this post: https://stackoverflow.com/questions/17819814/how-can-you-get-the-clipboard-contents-with-a-windows-command

I'm calling powershell to output the contents of the clipboard to a file, as in:

powershell.exe -command "Get-Clipboard" > myFile.txt

This completely changes the appearance of my terminal and I think I might be running powershell, or something. See "before" and "after redirecting to a file", below. It also truncates my terminal after about ~3/4 of the screen.

You'll note that the window description now says "powershell.exe". But I can still run linux commands, and I have access to functions and aliases defined in my bashrc, so it's not like I'm suddenly in a powershell environment.

What's odd is that if I run, powershell.exe -command "Get-Clipboard" (ie without redirecting) it outputs the clipboard contents to the terminal without affecting my terminal appearance.

Typing ctrl-c does nothing. ctrl-d or typing exit just kills the terminal.

Any ideas about what's going on?

Before:

enter image description here

After redirecting to the terminal:

enter image description here

After redirecting to a file:

enter image description here

12
  • 1
    Thanks for reposting over here. I did try this out when I saw the other question, and I wasn't able to reproduce it. It's entirely too coincidental that both you and @jeff-tang came across this today (within hours of each other). Did you install or update anything recently (Windows Terminal, Windows, etc.)? I'm thinking (based on the fact that I can't reproduce it yet, and the fact that at least two people came across it today), that it's probably a bug introduced in a new release of something. But just not sure yet. – NotTheDr01ds Jan 15 at 20:14
  • I'm on Windows Terminal 1.4.3243.0, which is the latest that I see in the store. I tested under both WSL1 and WSL2, both with bash (and also sh, and fish shell) on Ubuntu 20.04 with all packages up to date as of a couple of days ago. I've tried powershell.exe -command get-clipboard | cat and powershell.exe -command get-clipboard > /dev/null. Everything is still intact on my terminal after this. – NotTheDr01ds Jan 15 at 20:21
  • Odd though it may be, I think it actually is a coincidence. I've only been using wsl for a few weeks, and this was just the first time I've needed to do this. I had actually wondered if this was a wsl1 v wsl2 thing, but @jeff-tang's question said he was using wsl2. Also, someone I know tried this using the hyper terminal (hyper.is) and apparently this doesn't happen. – cmuyehara Jan 15 at 20:23
  • 1
    Okay - so that does not happen when I actually use Windows Terminal. It's something specific to the Ubuntu terminal. – cmuyehara Jan 15 at 20:49
  • 1
    I posted this same problem on stack overflow. I've never used this command before today, so I don't know if this is a change of behavior. I saw this command on reddit yesterday and thought it would be useful. I've also redirected stderr so I don't think it's some weird console control codes. And I'm not even sure if that's a windows thing or just an xterm/vt100 thing – Jeff Tang Jan 15 at 21:04
1

Based on the comments and our testing, this seems to be a problem with the "Ubuntu terminal" (the terminal launched with the Ubuntu WSL distribution from the Windows Start menu). Other terminals such as hyper.js, Windows Terminal (from Microsoft, in the Store), and the default Windows terminal (launched when you use the "bash" command from the Start menu) all seem to work correctly.

Recommendation - Install an alternate terminal. My personal preference is Windows Terminal.

3
  • That's sufficient for me. I was a little concerned that it was causing multiple powershell processes to run, but I checked and that does not seem to be the case. Thanks for the help! – cmuyehara Jan 15 at 21:40
  • 1
    I stand corrected (not the first time).. I will delete my post. :P – Señor CMasMas Jan 15 at 22:19
  • Well, at least you caveated it with "As far as I'm aware ..." ;-) – NotTheDr01ds Jan 15 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.