File '>' not found (Errcode: 2)

This is the place for queries that don't fit in any of the other categories.

File '>' not found (Errcode: 2)

Postby shahriyar.r » Thu Aug 29, 2013 10:30 am

Dear experts i have encountered an interesting issue while running terminal command from Python..
Here is my Python code:

Code: Select all
import os
import subprocess
import shlex
import configparser


class BinlogToTxt:
    def __init__(self,conf = 'datadir.conf'):
        con = configparser.ConfigParser()
        con.read('datadir.conf')
        bolme=con.sections()
        DB=bolme[0]
       
        self.originalbinlogdir=con[DB]['originalbinlogdir']
        self.txtdir=con[DB]['txtdir']


    def binlog_show(self):
        print("Your binary log list: ")
        for files in os.listdir(self.originalbinlogdir):
            print(files)



    def binlog_convert(self):
        self.binlog_show()
        select=input("Which one convert to .txt file?(Give fullname): ")
        subselect=select.find('0')
        binselect=select[subselect:]

        args = '/usr/bin/mysqlbinlog -vv --base64-output=DECODE-ROWS %s/%s > %s/%s.txt' % (self.originalbinlogdir,select,self.txtdir,binselect)

        print(args)
        args=shlex.split(args)
        print(args)

        #p=subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        p=subprocess.Popen(args)
        return p

       

a = BinlogToTxt()
a.binlog_convert()


here ise datadir.conf:

Code: Select all
[MySQL]
mysql = /usr/bin/mysql
mycnf = /usr/my.cnf
mysqlbinlog = /usr/bin/mysqlbinlog
mysqladmin = /usr/bin/mysqladmin
remoteconnection = "--user=remote --password=12345 --host=192.168.1.103"
binlogsyncdir = /home/sh/remote_binlogs
myoptions= "--read-from-remote-server --raw --to-last-log"
originalbinlogdir = /home/sh/remote_binlogs
txtdir = /home/sh/txtdir


When i run this code get error:
Code: Select all
/usr/bin/mysqlbinlog: File '>' not found (Errcode: 2 - No such file or directory)


'>' -- is this a directory? how i can solve this?
Last edited by Yoriz on Thu Aug 29, 2013 12:03 pm, edited 2 times in total.
Reason: First post lock
shahriyar.r
 
Posts: 7
Joined: Thu Aug 29, 2013 9:50 am

Re: File '>' not found (Errcode: 2)

Postby stranac » Thu Aug 29, 2013 12:41 pm

That's not how you redirect output using subprocess.Popen()
You should just give it a file object as it's stdout parameter.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 882
Joined: Thu Feb 07, 2013 3:42 pm

Re: File '>' not found (Errcode: 2)

Postby shahriyar.r » Thu Aug 29, 2013 6:05 pm

stranac wrote:That's not how you redirect output using subprocess.Popen()
You should just give it a file object as it's stdout parameter.


Could you show exactly how i must run this? i am a newby in Python :?
shahriyar.r
 
Posts: 7
Joined: Thu Aug 29, 2013 9:50 am

Re: File '>' not found (Errcode: 2)

Postby stranac » Thu Aug 29, 2013 6:19 pm

Something like this should work:
Code: Select all
args = ['/usr/bin/mysqlbinlog', '-vv', '--base64-output=DECODE-ROWS',
        '%s/%s' % (self.originalbinlogdir, select)]
filename = '%s/%s.txt' % (self.txtdir, binselect)

with open(filename, 'w') as f:
    # looks like subprocess.call() might be a better choice for what you want
    # but subproces.Popen() call would look pretty much the same
    subprocess.call(args, stdout=f)


Edit:
Also, try using os.path.join()
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 882
Joined: Thu Feb 07, 2013 3:42 pm

Re: File '>' not found (Errcode: 2)

Postby shahriyar.r » Thu Aug 29, 2013 8:00 pm

Thanks. I was searching solution for a day but find only here :D
Yes as you say both work correctly:

subprocess.Popen(args,stdout=f)
and
subprocess.call(args, stdout=f)
shahriyar.r
 
Posts: 7
Joined: Thu Aug 29, 2013 9:50 am


Return to General Coding Help

Who is online

Users browsing this forum: stranac and 2 guests