Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are response codes for 256 and 512 for os.system in python scripting

Tags:

python

When i ping servers with os.system in python i get multiple response codes. Command used - os.system("ping -q -c 30 -s SERVERANME")

  • 0 - Online
  • 256 - Offline
  • 512 - what does 512 mean ?
like image 531
DevUser Avatar asked Mar 06 '19 01:03

DevUser


People also ask

What is a response in Python?

When one makes a request to a URI, it returns a response. This Response object in terms of python is returned by requests.method(), method being – get, post, put, etc. Response is a powerful object with lots of functions and attributes that assist in normalizing data or creating ideal portions of code.

What is status-code in Python?

Python - Request Status Codes. After receiving and interpreting a request message, a server responds with an HTTP response message. The response message has a Status-Code. It is a 3-digit integer where first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role.

What is this response code used for?

This response code is used when the Range header is sent from the client to request only part of a resource. Conveys information about multiple resources, for situations where multiple status codes might be appropriate.

What is the status-code of the response message?

The response message has a Status-Code. It is a 3-digit integer where first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role. There are 5 values for the first digit: It means the request was received and the process is continuing.


1 Answers

Per the docs:

On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent.

And the wait docs say:

Wait for completion of a child process, and return a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.

So 0, 256 and 512 correspond to ping exiting normally (not killed by signal) with exit statuses of 0 == 0 << 8 (0 traditionally means "success"), 256 == 1 << 8 (1 typically means "normal" failure) and 512 == 2 << 8 (not consistent, but 2 is frequently used to indicate an argument parsing failure). In this case, you passed -s without providing the mandatory value (packetsize) that switch requires, so an exit status of 2 makes sense.

like image 198
ShadowRanger Avatar answered Oct 18 '22 03:10

ShadowRanger