Following my OSX bash bug discovery the other week what about this baby.
Just to let you guys know, since my post Sinclair Spectrum days where it was impossible to do a syntax error I do a great deal of syntax juggling to see what works on the few languages that I know, and I have done it for years, a form of hacking if you like......
I found this and mentioned it to someone I know on a python list.
NOTE: The help in the second code snippet. It seems that the string length is printed to sys.stderr .
The guy said it was part of the standard library in Version 3.x.x, NOT in Version 2.7.x and lower.
This IS actually in Python 3.x's standard library!? <Shock!>
I don't know about the latest Python 3.6.1 as I have not installed it yet.
The use of Python's exit function here is none standard but it does NOT give an error.
INSTEAD it gives a return code of the string length.
Surely this HAS to be a bug?
OUCH!
The help(sys.stdout.write) on python3.5.x
Comments anyone?
Oh dear this is even worse!
It even does it in a called script from a bash script...
Results, same system as before...
EDIT:
Makes one wonder what a string greater than 255 characters would give, (wrap around the 255 bash shell boundary). What about returning these values to other languages and OSes?
Last edited by wisecracker; 06-08-2017 at 10:53 AM..
Reason: See EDIT:
For me, python is a large snake, or a flying circus, but what you show above would be the expected behaviour and absolutely makes sense to me. In the languages I know, exit (or similar) can take a value, even from a variable or a function, which becomes the program's "exit code". Why not deploy write's return value of 15? awk example:
For values greater than 255, usually the lower byte is evaluated.
I seem to recall you making a thread about this before, and it was determined that printing the return values to stderr was a feature Python does in interactive mode.
As for it returning 15? It's actually very standard to give exit() a code in most languages, if Python didn't it'd be the weird one. And it is documented, here:
Quote:
The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like. Most systems require it to be in the range 0–127, and produce undefined results otherwise.
Yes, the exit value is communicated to BASH, the calling process, that is its function, to tell it whether the program succeeded or failed.
Last edited by Corona688; 06-08-2017 at 12:14 PM..
@ RudiC...
How about this then?
Result:-
@Corona688...
No that was something entirely different using the shell's exit, it is on here I will find the pointer.
EDIT:
I appreciate this is hypothetical but if I can create this then a deep professional would know fully how to exploit it.
---------- Post updated at 07:36 PM ---------- Previous update was at 06:58 PM ----------
Quote:
Originally Posted by RudiC
For me, python is a large snake, or a flying circus, but what you show above would be the expected behaviour and absolutely makes sense to me. In the languages I know, exit (or similar) can take a value, even from a variable or a function, which becomes the program's "exit code". Why not deploy write's return value of 15? awk example:
For values greater than 255, usually the lower byte is evaluated.
'END' just hangs on this machine so 'BEGIN' instead.
Hmmm, so this is normal proceedure?
Last edited by wisecracker; 06-08-2017 at 03:37 PM..
Reason: See EDIT.
@ RudiC...
How about this then?
.
.
.
exit(os.system(text))
.
.
.
Back inside bash shell with exit code 0...
I can't tell what value os.system.text will return. Is it a function returning successfully? Certainly not an integer value. I ponder a pointer of which the low order byte is 0.
Quote:
'END' just hangs on this machine so 'BEGIN' instead.
It doesn't "hang", it reads from stdin / tty, so hit a <CTRL>-D as an EOF char.
Quote:
Hmmm, so this is normal proceedure?
Yes, exactly ls -l completed successfully and returned a 0.
Last edited by RudiC; 06-08-2017 at 05:00 PM..
Reason: typo
So one is allowed to execute code AFTER exit has been called even if it is an ASCII string inside a variable, from awk AND Python and I thought Python was strict, what about Perl and others?
Awk's exit is a statement and Python's is a function.
Maybe it is just me but this should never be allowed to happen if the RC is not an integer. BTW thanks for the Ctrl-D heads up, I had forgotten all about that, however 'ls -l' is still executed.
Hi Corona688...
It was this, it always needs a redirection to a file for it to work however, so nothing like the other two and technically MUCH safer:-
And yes, I know why the 'text' file_length reads zero, 0.
Hi all...
As you know I like making code backwards compatible for as many platforms as possible.
This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Hi all,
I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine..
Below is the code I am trying:
#!/usr/bin/env python
import wmi
c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
(Apologies for any typos.)
OSX 10.12.3 AND Windows 10.
This is for the serious Python experts on at least 3.5.x and above...
In script format sys.stdout.write() AND sys.stderr.write() seems to work correctly.
Have I found a serious bug in the interactive sys.stdout.write() AND... (2 Replies)
I am working on requirement on spreadsheet in python scripting.
I have a spreadsheet containing cell values and with background color.
I am able to read the value value but unable to get the background color of that particular cell.
Actually my requirement is to read the cell value along... (1 Reply)
Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here.
I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
#!/bin/bash
if then
#echo "infinite loop"
exit 0
fi
when I run this file I get the following error:
./test_infinite_loop: line 5: syntax error near unexpected token `fi'
./test_infinite_loop: line 5: `fi'
:confused: (4 Replies)
Hi All,
I am using Red Hat Linux on my servers. The problem that I am facing is, sometimes the /opt usage on the server shows used percentage as 100% , when actually it is simply 20%.
When I reboot the system, it comes back to 20%.Is this a bug in the system or my settings have gone wrong... (1 Reply)