Is there a way to dynamically change the input to a system call in google colab?

298 views Asked by At

I was wondering if there is a way to dynamically change a subprocess call. Right now I'm running into a problem where I can only input a static string into a subprocess call for google colab and no way to input a string variable.

Here is an example of what I'm trying to do:

for file in list_of_files:
   cflow_data = !cflow file

and I am struggling to find a way to get that dynamic string value to be outputted to the subprocess call in google colab. I've tried a variety of methods including:

  • subprocess.Popen() followed by .communicate()
  • os.system()
  • subprocess.call()

and to no avail. If anyone has any insight into this or if it is even possible in Goolge Colab that would be great. Thanks!

1

There are 1 answers

0
Alfred T On

After trying more methods I found a solution.

cflow_cmd = ["cflow","-l","/file/path"]
for file in file_list:
   cflow_data = subprocess.check_output(cflow_cmd)
   cflow_data = cflow_data.decode(locale.getdefaultlocale()[1])

Which takes the system output and converts it to a byte string and then converts that byte string to a string