0

I want to invoke a specific command shell in python to execute some scripts. For exemple, in R, I use:

system2(os_shell = "C:/Program Files (x86)/pgAdmin III/1.18/pg_dump.exe", args = "very long argument")

Thanks to this code, I can backup my Postgresql's tables with a for loop.

Problem: I didn't find an equivalent in Python.

  • Does this answer your question? [How to execute a program or call a system command?](https://stackoverflow.com/questions/89228/how-to-execute-a-program-or-call-a-system-command) – Yevhen Kuzmovych Jul 16 '21 at 10:04
  • This has nothing to do with Postgres. Postgres will not be involved until *after* your shell script makes a connection. – Belayer Jul 16 '21 at 18:00

1 Answers1

0

If you just want to execute a application with args in a shell you can do that very easily with os.system

import os
os.system("'C:/Program Files (x86)/pgAdmin III/1.18/pg_dump.exe' very long argument")

Tho I would recommend subprocess.call or subprocess.run

import subprocess
subprocess.call(["'C:/Program Files (x86)/pgAdmin III/1.18/pg_dump.exe'", "argument1", "argument2"]) #and you can add as many arguments you want
Robiot
  • 98
  • 10