0

I've a problem recently, that Im not really capable to solve..

Here is a script

!/bin/bash

ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

The export will be simply your own IP Address

192.168.2.1

So far so good but then I go in Python and write

str(os.system("./GrabOwnIP.sh"))

I'll get a different output

192.168.2.1

0

I just want a variable thats keeping this information itself but then I write

OWNIP = str(os.system("./GrabOwnIP.sh"))

Then it will just give me

0

I also tried to use the line from the bash script itself in the Python one but the same results occured

Community
  • 1
  • 1
tester
  • 13
  • 2
  • 1
    What does this have to do with `export`? `export` is for creating environment variables that are inherited by child processes. Your question is about output, not export. – Barmar Jun 14 '18 at 22:16

1 Answers1

0

os.system() returns the exit code. Use subprocess.check_output to capture the standard output of the command.

choroba
  • 231,213
  • 25
  • 204
  • 289