robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
396 stars 48 forks source link

platform independent shell output #69

Closed Danitegue closed 6 years ago

Danitegue commented 6 years ago

Hi Rob. I'm doing a python script to redirect the system call with the SHELL statement.

What about to replace in dos.py, launch function, line 172:

lines, shell_output[:] = b''.join(shell_output).split('\r\n'), []

by:

lines, shell_output[:] = b''.join(shell_output).splitlines(), []

I think the \r\n will work only on windows, while splitlines detects the type of end of line, and it would work in all operative systems, not?

robhagemans commented 6 years ago

Hi,

This has been almost completely rewritten in the development branch, so please refer to that one if you're developing something new.

Generally it's been written and tested to interface with a number of likely shells, in particular CMD.exe (Ansi and utf-16) as well as winecmd on Linux. Unfortunately not all python's cross platform line ending translations work as advertised, so I'm quite hesitant to use them as I find them unpredictable. However, what's there currently has been tested quite extensively over the past month so I'm planning to keep it as is... I would suggest that the new script simply follows Cmd's interface and it should work ok.

Danitegue commented 6 years ago

Ok, I will give a look to the develop branch.

I say this because if in my customized shell script I put something like:

print "Brewerfunctions.py, Emulating shell_copy function."

python adds a \n terminator there by default, while the actual dos.py is expecting a windows \r\n to split the shell_output. I can modify the script to add a \r\n to the return, but not to replace the \n that python add by default after a print. (At the end we will have \r\n\n). And the option to add only a \r I don't know how would work in other OS.

But I will try in the develop branch

robhagemans commented 6 years ago

For the \r\n, you could use sys.stdout.write() instead of print, which will give you more control as it does not add any line terminators by itself.

Danitegue commented 6 years ago

Ok, the customized shell works fine with sys.stdout.write() and the old dos.py.

I will wait for your new release, for testing the new dos.py.

2018-03-26 19:28 GMT+00:00 Rob Hagemans notifications@github.com:

For the \r\n, you could use sys.stdout.write() instead of print, which will give you more control as it does not add any line terminators by itself.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/robhagemans/pcbasic/issues/69#issuecomment-376283515, or mute the thread https://github.com/notifications/unsubscribe-auth/AYutGMdkBhYCRWblcsuoKrV8FjvuEZoKks5tiUFfgaJpZM4S7Fyc .

--

Daniel Santana Díaz, Danitegue@gmail.com

robhagemans commented 6 years ago

Hi @Danitegue , I've put the new release online, you can install with pip install pcbasic or use the archive at https://github.com/robhagemans/pcbasic/releases/tag/v2.0.dev3