vitorbaptista / shellshare

Live terminal broadcasts
https://shellshare.net
Apache License 2.0
223 stars 23 forks source link

running shellshare in MS Windows #55

Closed edmundlaugasson closed 6 years ago

edmundlaugasson commented 6 years ago

Tried to run in MS Windows 10 build 1703 using Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 and got following errors: python.exe .\shellshare.py --server address.ee:3000 --room roomname --password password output: 'tput' is not recognized as an internal or external command, operable program or batch file. 'tput' is not recognized as an internal or external command, operable program or batch file. Traceback (most recent call last): File ".\shellshare.py", line 163, in <module> size = terminal_size() File ".\shellshare.py", line 50, in terminal_size cols = int(cols.stdout.read().strip()) ValueError: invalid literal for int() with base 10: b'' Having C:\Users\user\AppData\Local\Programs\Python\Python36-32\ also in PATH, so python.exe will run anywhere. Used Powershell to run that command to start shellshare. At the same time under Linux my server is working fine. Running own server as shellshare.net is quite often offline. Using Linux my own but just thought that possibly also in MS Windows it could work as Python is available also there. EDIT: installed WSL in MS Windows and tried to run there using python3 and did not succeed, the following error message: script: cannot set signal handler: Function not implemented

edmundlaugasson commented 6 years ago

Commented out lines 163-167 size = terminal_size() if (size['rows'] > 30 or size['cols'] > 160): print('Current terminal size is %dx%d.' % (size['rows'], size['cols'])) print('It\'s too big to be viewed on smaller screens.') print('You can resize it anytime.')

and then error messages: Unhandled exception in thread started by <function stream_file at 0x02CB92B8> Traceback (most recent call last): File ".\shellshare.py", line 82, in stream_file f = open(path, 'rb') PermissionError: [Errno 13] Permission denied: 'C:\\Users\\user\\AppData\\Local\\Temp\\tmpdpdo939w' 'script' is not recognized as an internal or external command, operable program or batch file. End of transmission. Do not understand why there is no permissions if the folder belongs to user

vitorbaptista commented 6 years ago

@edmundlaugasson Sorry for taking long to answer. I haven't tested shellshare on Windows, as I don't have access to a Windows machine. Although it should work with Cygwin or a Bash-like terminal, I'm not sure about Powershell.

The issues you're having seem to be:

You can "solve" the tput issue by commenting out the code, as you've done, or implementing a OS-independent version of getting the terminal screen size, but the script software is a bit more complex. It seems Cygwin does include it (https://superuser.com/a/662185), so it should be possible to run shellshare on Windows with some modifications, but I don't know how well it'll work.

If you have some time and would like to contribute, it would be amazing to add Windows support for shellshare.

edmundlaugasson commented 6 years ago

@vitorbaptista Thanks for feedback! To be honest, I am not a programmer. Currently it would be too challenging for me to achieve programming skills on the level that would allow me to fix the mentioned issue(s). But I contributed with following links of official, legal sources to acquire latest MS Windows either as virtual machine or ISO file to install by your own.

To be honest - I have MS Windows installed only in Virtual Machine and anyone can freely and legally download MS Windows ISO - going there from MS Windows itself does not give an ISO but using UNIX-like OS gives you ISO directly. Using user agent switcher in MS Windows gives also ISO if you change your web browser identity to some UNIX-like OS. Installing MS Windows 10 does not require a product code - yes, the only legal MS Windows is an activated one (as MS says) but just for temporary testing purposes such approach can be used. Unactivated MS Windows actually works forever and even all updates can be installed. So basically it is not limited to use but MS just claims that unactivated copy isn't legal.

There is also always MS TechNet Evalcenter where MS Windows is usually limited to 90 days, official and legal place as well. If 90 days are over, you can download and evaluate again next 90 days. Here is direct link (LTSB explained: link1, link2, LTSB is not suggested to use - only for special-purpose devices). For MS Windows 10 release information, please see here.

Even more - MS is sharing ready-to-use virtual machines - also working 90 days, legally, officially. So it would be relatively easy to acquire either ready-to-use MS Windows 10 virtual machine or download ISO and install by your own - all from official, legal sources directly from software creator. If there could be created a OS-independent version then it would praise as it could be - python works on different platforms.

Not very much understood, why there is a need to determine the terminal size - usually people run shellshare regardless of terminal size. It would be immediately understood when it does not fit onto screen as people test the result - how it would be seen in browser. If people do not test it, soon or later they will realize it and correct terminal size if needed.

While python is installed under MS Windows, people never will install any additional software like Cygwin. As python claims to work on different platforms and is usually installed in universities who are teaching programming or at least using it for management purposes.

The hardest part seems for me to replace the script for MS Windows....

vitorbaptista commented 6 years ago

This seems to be quite complex, based on this issue https://github.com/asciinema/asciinema/issues/150. You're probably already able to run it using Cygwin or the Ubuntu subsystem in Windows, but I'm unable to test it further.

I'm closing this issue now as a wontfix, but feel free to reopen (or open another issue) if you face some problems. If anyone reading this would like to give it a go in supporting Windows, please let me know :+1:

edmundlaugasson commented 6 years ago

Looks like #2 promises to bring that ability to free from script and make possible to run under any OS that supports Python.

hoytpr commented 5 years ago

It can be run on Windows 10_1803 in CygWin64 using Python v. 3.6 but haven't tested other versions (except it did not seem to work with python 2.7). For some reason, I had trouble until upgrading the 'pip' command. In Cygwin after updating to python 3.6, you need to call python with python3 and so python3 -m ensurepip was needed. Then simply

$ curl -sLo shellshare https://get.shellshare.net
$ python shellshare

worked. I'm not a programmer, So can't help much more. I tried using a conda prompt but received the same errors as seen before i.e.

'tput' is not recognized as an internal or external command,
operable program or batch file.
'tput' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
  File "shellshare", line 163, in <module>
    size = terminal_size()
  File "shellshare", line 50, in terminal_size
    cols = int(cols.stdout.read().strip())
ValueError: invalid literal for int() with base 10: b''

Have not tried a Gitbash prompt yet. EDIT: Doesn't work on GitBash. Peter

vitorbaptista commented 5 years ago

Thanks for your report, @hoytpr. I think I solved the issue you had on the Conda prompt, but I don't have access to a Windows machine so I can't test it. Could you try it out?

Simply do:

$ curl -sLo shellshare https://raw.githubusercontent.com/vitorbaptista/shellshare/extract-terminal-size-in-windows/public/bin/shellshare
$ python shellshare

I'm hoping you won't see the error with tput anymore, and everything will work as expected. Possibly it will work on gitbash as well.

hoytpr commented 5 years ago

New error. I ran the conda prompt as administrator but the new error (using base conda or the condaFQC environment I had set up) is:

(condaFQC) C:\Users\Hoyt>python shellshare
Sharing terminal in https://shellshare.net/r/ig0jogyEKN9zCBKgl8
'script' is not recognized as an internal or external command,
operable program or batch file.
Unhandled exception in thread started by <function stream_file at 0x0000000003CC6278>
Traceback (most recent call last):
  File "shellshare", line 115, in stream_file
    f = open(path, 'rb')
IOError: [Errno 13] Permission denied: 'c:\\users\\hoyt\\appdata\\local\\temp\\tmpnzmiha'
End of transmission.

There is a shellshare at https://shellshare.net/r/ig0jogyEKN9zCBKgl8, but non functional.


I asked a couple geniuses at our HPPC group and one of them told me he thinks he has figured it out, and had it working in Windows Ubuntu. I had NOTHING to do with this (and don't fully understand it because I'm just a Biologist), and told him to contact you. "I think you should be able to get it working in git-bash with a simple modification. This line near the end is the one that starts GNU script: subprocess.call('script %s %s' % (shell_args, tmp.name), shell=True) Here is the (as yet untested) modification that should make it work in git-bash, Cygwin, and MSYS: subprocess.call('mintty.exe --log %s --exec bash' % (tmp.name), shell=True) This is based on what I setup in shell-transcript, which does a similar thing but without the live-stream + client/server model. You should also be able to substitute “bash” with “cmd.exe” or “powershell.exe” or just about any other text-based program too.

Evan Linde Research Cyberinfrastructure Analyst Oklahoma State University"

hoytpr commented 5 years ago

Update, after updating my condaFQC environment to python 3.6 the error changed slightly:

(condaFQC) C:\Users\Hoyt>python shellshare
Sharing terminal in https://shellshare.net/r/f3S9LBJMAIaxi36olP
Unhandled exception in thread started by <function stream_file at 0x000002651830F268>
Traceback (most recent call last):
  File "shellshare", line 115, in stream_file
    f = open(path, 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Hoyt\\AppData\\Local\\Temp\\tmpk06927lc'
'script' is not recognized as an internal or external command,
operable program or batch file.
End of transmission.
hoytpr commented 5 years ago

Using GitBash:

$ python shellshare
Current terminal size is 65x147.
It's too big to be viewed on smaller screens.
You can resize it anytime.
Sharing terminal in https://shellshare.net/r/WK6UVcMdBKTTN9adXM
'script' is not recognized as an internal or external command,
operable program or batch file.
Unhandled exception in thread started by <function stream_file at 0x0000028272BCE378>
Traceback (most recent call last):
  File "shellshare", line 115, in stream_file
    f = open(path, 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Hoyt\\AppData\\Local\\Temp\\tmpw1_0zjq4'
End of transmission.

I'll see if I can do anything about the permission errors. Peter

vitorbaptista commented 5 years ago

@hoytpr Thanks for testing the script. Unfortunately, the exceptions you're getting happen because you don't have the software GNU Script. As far as I know, it's only available on Windows when using Cygwin. Maybe when using the Windows Subsystem for Linux (WSL) as well, but I'm not sure. So this won't work.

Please thank your colleage for me. I didn't know about mintty.exe, and it seems it could solve the problem. However, I'm worried to do this change without testing it myself, as I don't know if the files it create (typescript) are the same as script, and worse: it seems mintty.exe isn't available by default on Windows, so the users would need to install it as well.

I'd love to have some help finding a solution that works out of the box on Windows, but I can't do it myself as I don't have a Windows machine. In the meantime, http://cygwin.org/ works fine with shellshare on Windows. I wrote about it on the shellshare FAQ at https://shellshare.net.

Thanks again for your help.

edmundlaugasson commented 3 years ago

Looks like now v1.1.0 has Windows support? How to properly install and use under Windows? Asked it as new issue #68