Python Forum
Difference between Python's os.system and Perl's system command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference between Python's os.system and Perl's system command
On Windows 10, I am converting a perl script to python, but I have a problem.

The command in the perl script file is:

Quote:system ("a dot exe file with 3 options");

In Python, I use the exact same argument in the following system call:

os.system ("a dot exe file with 3 options")
Note: The two above commands have the exact same string!

My problem is that the executable program is supposed to create 4 files in C:\Temp. The perl script does create all 4 files as it is supposed too. But, the Python script creates only 1 file then gives me a popup window saying, "COULD NOT OPEN THIS C:\TEMP". The program then deletes the file it created.

I know nothing about the executable. It was created my someone years ago.

I tried changing one property of the executable file, so that all users execute it as an administrator. But, that didn't solve the problem.

I tried making all the files involved to be readable but that also didn't work.

Is there a difference between the Perl "system(...)" command and the Python "os.system(...)" command that I should be aware of?

Should I use a different command instead of "os.system()"?

Thank you,
if your string has c:\temp then \t is escape sequence (i.e. TAB). use forward slash, raw string or escape the backslash.

Also is recommended over os.system
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


It seems that subprocess is closer to the Perl system command.
The Python os.system() function invokes the system shell to launch the command.

system() takes a list of strings, each element after the first is a command parameter

os.system() takes a single string["ls", "-l"]) optionally takes a list of strings."exit 1", shell=True) or a single string
(Nov-27-2019, 09:07 PM)buran Wrote: if your string has c:\temp then \t is escape sequence (i.e. TAB). use forward slash, raw string or escape the backslash.

Also is recommended over os.system

  1. Are there any problems with me first trying to use a variable with the below code?
  2. How would you modify/improve this specific code?
  3. Do I have alternatives?
  4. Should I try to replace each single backslash with two backslashes? How can I do this?

the_command = "a dot exe file with 3 options" (r'the_command, shell = True)
r' is not some magical operator that would apply to abitrary expressions. Instead, r'...' is a special kind of literal string where the \ character is taken literaly instead of being used as an escape character. Thus you can write
the_command = r"a dot exe file with 3 options" (the_command, shell = True)
Most of the time however, shell=True is superfluous and/or detrimental and it is better to split the command in a list of arguments
import shlex
the_command = shlex.split(r"a dot exe file with 3 options") (the_command)
Not required
If you run the command in a terminal, what is the exact command that works in the terminal (cmd window)?
Not required
It is meaningless to try things randomly. Find the command that works in a Cmd window first, outside of any scripting language.
Not required

Possibly Related Threads…
Thread Author Replies Views Last Post
  Change icons of system rizzla 1 165 Jan-28-2021, 03:30 PM
Last Post: Marbelous
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 5,942 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  how to find difference between fake driving license or real using python? pjaymn 2 262 Dec-20-2020, 08:41 PM
Last Post: jefsummers
  How to link Sublime Text 3 Build system to Python 3.9 Using Windows 10 Fanman001 1 430 Nov-27-2020, 10:51 PM
Last Post: snippsat
  Solve system of equations Sancho_Pansa 19 836 Oct-27-2020, 08:15 AM
Last Post: Sancho_Pansa
  function call at defined system time? Holon 5 520 Oct-06-2020, 03:58 PM
Last Post: snippsat
  Solve a system of linear equations with binary variables lopeslimagabriel 3 382 Sep-24-2020, 07:09 AM
Last Post: scidam
  system of inequalities in python fiel 1 359 Sep-12-2020, 06:07 AM
Last Post: DPaul
  How could i change the python interpreter path of os.system() 12019202386 2 392 Sep-02-2020, 06:58 AM
Last Post: DeaD_EyE
  python 3 find difference between 2 files pd007 2 520 May-22-2020, 01:16 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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