Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass variable to subprocess
#4
(Apr-12-2022, 11:32 AM)paulo79 Wrote:
(Apr-11-2022, 11:53 PM)snippsat Wrote: String formatting and now use f-string new in Python 3.6 ➡
>>> VARIABLE = 12
>>> s = f"cat /tmp/logall | sort -u | grep -v {VARIABLE}"
>>> s
'cat /tmp/logall | sort -u | grep -v 12'

Is there a way to in python 2.7? I cannot use 3 yet.

I found it:
>>> VARIABLE=12
>>> v_num_final_distinct_grid_disks_per_cell_and_dg = subprocess.check_output("cat /tmp/logall | sort -u | grep -v {}".format(VARIABLE), shell=True);
>>>
>>> print(v_num_final_distinct_grid_disks_per_cell_and_dg)
10

>>> VARIABLE=10
>>> v_num_final_distinct_grid_disks_per_cell_and_dg = subprocess.check_output("cat /tmp/logall | sort -u | grep -v {}".format(VARIABLE), shell=True);
>>> print(v_num_final_distinct_grid_disks_per_cell_and_dg)
12

>>>
Reply


Messages In This Thread
Pass variable to subprocess - by paulo79 - Apr-11-2022, 11:36 PM
RE: Pass variable to subprocess - by snippsat - Apr-11-2022, 11:53 PM
RE: Pass variable to subprocess - by paulo79 - Apr-12-2022, 11:32 AM
RE: Pass variable to subprocess - by paulo79 - Apr-12-2022, 11:40 AM
RE: Pass variable to subprocess - by DeaD_EyE - Apr-12-2022, 12:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 910 Jul-27-2023, 12:40 AM
Last Post: tester_V
  how to pass the interactive string to Popen subprocess maiya 1 1,908 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,595 Sep-07-2020, 08:02 AM
Last Post: perfringo
  How to pass multiple values from one sample to nc variable? Baloch 0 1,885 Jun-01-2020, 09:27 PM
Last Post: Baloch
  How to pass variable as an argument to be used in a function? t4keheart 8 3,703 Jan-16-2020, 01:37 PM
Last Post: buran
  Pass by reference vs Pass by value leodavinci1990 1 2,243 Nov-20-2019, 02:05 AM
Last Post: jefsummers
  How to pass a variable to subprocess.check_call champweller 1 2,847 May-26-2019, 07:10 AM
Last Post: heiner55
  Pass variable script return twice output problem Faruk 8 4,495 Dec-26-2018, 11:57 AM
Last Post: Faruk
  how to pass a variable from a file to a 2d file sylas 1 2,240 May-05-2018, 02:46 AM
Last Post: micseydel
  [subprocess]>Run a cmd command and get output into a variable CSA75 4 22,915 Mar-13-2017, 09:33 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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