Python Forum
Os command output in variable shows wrong value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Os command output in variable shows wrong value
#1
I have this :

v_num_distinct_phy_disks_in_cells=os.system('cat /tmp/p_count_num_phy_disks_all_cell | sort -u | wc -l')
The content of file is :
cat /tmp/p_count_num_phy_disks_all_cell
12
12
12
If I run manually it shows correct as value of distinct number is 1:
cat /tmp/p_count_num_phy_disks_all_cell | sort -u | wc -l
1
If I run in Python I get this:
>>> v_num_distinct_phy_disks_in_cells=os.system('cat /tmp/p_count_num_phy_disks_all_cell | sort -u | wc -l')
1
>>> print(v_num_distinct_phy_disks_in_cells)
-1
Why it is showing -1 ?
Reply


Messages In This Thread
Os command output in variable shows wrong value - by paulo79 - Apr-09-2022, 03:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,739 Mar-27-2023, 07:38 AM
Last Post: buran
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 1,010 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,222 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,819 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  How to combine two output in one variable? ilknurg 2 1,303 Aug-01-2022, 09:31 AM
Last Post: Gribouillis
  How to write a part of powershell command as a variable? ilknurg 2 1,197 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  ModuleNotFound but pip shows module installed biscotty666 2 1,651 Jul-14-2022, 05:17 PM
Last Post: Axel_Erfurt
  How to use a variable in linux command in python code? ilknurg 2 1,678 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Command output to Variable ironclaw 1 1,847 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  For loops returning wrong output Nighthound21 1 2,020 May-03-2021, 03:43 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020