running external python program from another program

Laxmi Kadariya

I have a python program gold.py located at /home/laxmi/Desktop/gold/gold.py in ubuntu. I have a python program test.py as test.py

import subprocess
subprocess.Popen("python", "Desktop/gold/gold.py")

I want this program to call the gold.py program and display the result from gold.py

error

 File "/usr/lib/python2.7/subprocess.py", line 660, in __init__
raise TypeError("bufsize must be an integer")
Steve P.

You're getting a TypeError. Since you're not passing keyword arguments, the second parameter is taken to be the buffer size, which must be an integer.

Change:

subprocess.Popen("python", "Desktop/gold/gold.py") 

To:

subprocess.Popen("python Desktop/gold/gold.py")

Here's the documentation for subprocess.Popen. The first parameter, the only required one is args:

args should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent and described below. See the shell and executable arguments for additional differences from the default behavior. Unless otherwise stated, it is recommended to pass args as a sequence.

NB:

If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

So, if this needs to be done, you would do:

subprocess.Popen("python Desktop/gold/gold.py", shell = True)

Please read about the security risks intrinsic to this in the link provided.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python exe errors when running by an external program

From Dev

Python 2.7 Running External .py Files in Program

From Dev

running external program in TCL

From Dev

Running a Python program from Go

From Dev

running python program in from website

From Dev

Runing an external program from another program Linux or cygwin

From Dev

Running a java program located at any location from another java program

From Dev

Calling a program from another in python

From Dev

Calling a program from another in python

From Dev

DOSBOX running external windows program

From Dev

Running Java Program in another Program gives error

From Dev

Running Java Program in another Program gives error

From Dev

Running keystrokes from program

From Dev

Debug Interactively a python code from another program

From Dev

Python running program backwards

From Dev

Running python program on linux

From Dev

Maximize window of another running program

From Dev

Maximize window of another running program

From Dev

Python: Spawning another program

From Dev

VIM: function that checks if external program is running

From Dev

Set external inputs in python program

From Dev

Pass variable from Python as input to external program with subprocess

From Dev

Running python code from a text file into your python program

From Dev

How to start one program from another program

From Dev

Running an interactive program from Ruby

From Dev

Running java program from terminal

From Dev

Running Program from USB drive

From Dev

Running a program installed from cabal

From Dev

Closing a running program from a process