[Tutor] subprocess.call not formatting date

Bob Williams linux at barrowhillfarm.org.uk
Tue Jul 8 18:44:10 CEST 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm using Python 2.7.6 on an openSUSE linux system.

I'm trying to convert a shell (bash) script to a python script, and everything's worked OK except this. The following line in the shell script

btrfs subvolume snapshot /home/bob/A3/documents /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`

creates a folder of the form

/home/bob/A3/docsnaps/14-07-08_17-32

ie. the name is a formatted date string, which is what I want.

In my python script, this

subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`')

creates a folder

/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`

In other words, it does not format the date, but takes the stuff between the backticks (`) as a string.

I tried adding shell=True, but got the following error:

Traceback (most recent call last):
  File "/home/bob/bin/btrfs-backup.py", line 55, in <module>
    subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`', shell=True)
  File "/usr/lib64/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 658, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Any suggestions, please?
- -- 
Bob Williams
System:  Linux 3.11.10-17-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.13.2
Uptime:  06:00am up 2 days 9:43, 5 users, load average: 0.00, 0.02, 0.05
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlO8H9gACgkQ0Sr7eZJrmU7fdACgkBqVXT+Ozb+XqmEFwhPBdmeX
NcgAnjY6YrbXcmUTAvgLPblk4rOWFAdH
=vfIY
-----END PGP SIGNATURE-----


More information about the Tutor mailing list