1

I wanted to try a script in python & Bash. I'm a python noob, so this more about learning.

The script should resize images (using imagemacgick) to 700 pixels. The bash script for this, resize_ji.sh, is simple:

#!/usr/bin/env bash

convert "$1" -resize 700 "$1_copy.jpg"

My python script, which includes a function to grab iso time to create a file (this comes later) is this:

# First we need to import the libraries we'll be using.
import datetime
import subprocess

# We want the file name to be yyyy-mm-dd. This is how we get it. 

def filename_datetime():
    date = datetime.datetime.now()
    filename = (date.strftime("%Y-%m-%d"))
    print(filename)

def image_resize():
    subprocess.call(["./resize_ji.sh","$1"], shell=True)


filename_datetime()
image_resize()

So as you can probably guess, I'm trying to path the positional parameter $1 into python; the idea is to execute it like so "./resize-image.py image.jpeg"

I'm not sure subprocess.call is the way to go here either. Not sure what I should use or how it is called so I can look it up.

martineau
  • 119,623
  • 25
  • 170
  • 301
Emax2020
  • 29
  • 2
  • As an aside, `shell=True` is _exactly_ wrong here. You either pass a list of tokens without `shell=True`, or a single string with `shell=True` and then the shell parses it into arguments. See also [Actual meaning of `shell=True` in subprocess](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess) – tripleee Dec 13 '21 at 05:02

0 Answers0