Can't we all just shut up?

Bridging The Gap Between Linux And Windows.

There are a lot of ways to connect Linux and Windows together: Cygwin, VNC, even Chrome RDP works. But what if you had to do something real specific, like recording a window on the Windows desktop from a Linux command line?

Well, I went down that well, and hit the bottom pretty hard. But, I came back up with nickels, and I’m going to share those nickels with the world.

What was I talking about again?

Oh, right, Linux to Windows via command line.

So, the easy go-to is Cygwin. Cygwin allows you to use Linux commands on Windows and start Linux daemons like sshd. Now, ssh’ing to Windows isn’t the hard part – it isn’t even trivial. The problem, however, is that when you ssh over to Windows, Windows puts you in a new session as that user, even if that user is logged in locally.

For example, on a computer named “PC,” you’re logged in as “User,” and on the desktop you’re running Firefox. If you open cmd and run tasklist /v you’ll see Firefox listed along with the Window Title. This is the local session. Now, you’re on a Linux box, and you ssh over to Windows via command line ssh User@PC. You log in, but you’re not in the same session as local session. You’re in a remote session. If you run tasklist /v now, you’ll see the Firefox process, but the Window Title will read N/A. You have no access to the desktop or the Windows.

This is a “head-first into a bucket of syrup” situation to anyone wanting to record the screen with ffmpeg. Ffmpeg requires the Window Title in order to record a window, and requires access to the desktop GUID to record the whole desktop. You have neither. This is normally the part where you start downloading everything remotely connected to VNC or X11, but wait, there is a simple solution: screen.

Screen is awesome. It’s a tool created by wizards deep in a cave who have a vast knowledge of how the Unixverse works. Screen is the Linux-version of an Elder Scroll.

Fig 1. Linux Man Pages

Screen is a window session manager for Linux. With screen, you can create sessions, which manage your terminals, your processes, and your windows, and allows you to switch around them on the fly. It’s just like how some Linux distros allow you to switch desktops. tmux is an alternative to this, too, and does basically the same thing.

But, what’s interesting about screen is that you can detatch from a session, and then reattach to it from a remote session. See where I’m getting at?

If you’re on your local session on PC as User, and you have Firefox up, open up Cygwin and run screen -S mySession. Cygwin will look like it has a hiccup real quick (type clear to fix any artifacts). Then type screen -ls to list the available sessions. You’ll see something like ####.mySession (Attached) (#### is the PID). We have a new session, and we’re currently using it. We can only have one connection to a session at a time, so type screen -D to detach. Run screen -ls again, and you’ll see ####.mySession (Detached) and that tells you it’s available. Go to your remote session. Type in screen -r ####.mySession and you’ll pick up that session. Now if you do tasklist /v you’ll see all User’s processes and the Window Titles. Problem friggin’ solved.

So there you go, guy who’s spying on a coworker, or YouTuber running a screen cap server. You are now a master Linux/Windows Bridger. This should give you exclusive rights to walk around your workplace/parents house with a wizard staff proudly. Put your system admins to shame with your knowledge.

Judge me.

Or get off my blog and get back to work, slacker. Those TPS Cover Pages aren’t printing themselves.



Published by


Computer Scientist for Engility, and Indie Game Dev from New Jersey. Loves playing games, and loves making them, too.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s