top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Python: bufsize must be an integer in subprocess.Popen

+2 votes
8,826 views

I am using the Linux system with python, i am running the following script

#!/usr/bin/python

import threading

import time

import sys
import subprocess
import datetime
import os
import time
import logging

proc1=subprocess.Popen("/root/Desktop/abc.py","64","abc",shell=True,stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

In this script i am calling the other script named abc.py which is located on the desktop with 64 and abc as its arguments I am getting the following error

File "/usr/lib64/python2.6/subprocess.py", line 589, in __init__
 raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Can someone help me?

posted Feb 23, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

When shell=True, the first argument should be string passed to shell.

So you should:

proc1=subprocess.Popen("/root/Desktop/abc.py 64 abc",
 shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
answer Feb 23, 2015 by Gurminder
Similar Questions
0 votes

Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses window? So for example, the terminal window is broken up into quadrants and the top right has htop running inside. I'd imagine this would involve some kind of terminal emulation as the dimensions of the window would need to be queried by htop.

+1 vote

The change in integer division seems to be the most insidious source of silent errors in porting code from python2 - since it changes the behavior or valid code silently.

I wish the interpreter had an instrumented mode to detect and report such problems.

0 votes

I was following an exercise in a book when I edited the code and came across something I did not get. Here is the relevant part of the code that works:

start=None #initialise 
while start !="": 
 start=input("nStart: ")

 if start:
 start=int(start)
 finish=int(input("Finish: ")) 

 print("word[",start,":",finish,"] is", word[start:finish])

I then changed the code to this:

start=None #initialise 
while start !="": 
 start=int(input("nStart: "))

 if start:

 finish=int(input("Finish: "))

 print("word[",start,":",finish,"] is", word[start:finish])

I combined the int conversion and the input on the same line, rather than to have two different statements. But got an error message:

Traceback (most recent call last):
 File "C:UsersFaisalDocumentspythonpizza_slicer.py", line 23, in 
 start=int(input("nStart: "))
ValueError: invalid literal for int() with base 10: ''

Could someone tell me why I got this error message?

...