Problem with executeCommandLine() and redirect >

Hello maybe someone can help me with an executeCommandLine() that includes a redirect to store the scanned picture in a file and not the terminal :slight_smile:

This is my rule:

		Item Scanning changed to ON
		var String print = "/usr/bin/sudo@@/usr/bin/scanimage@@--resolution=150@@--format=tiff@@>/media/scan/scan_$(/bin/date +%Y%m%d_%H%M%S).tiff"
		var String answer = executeCommandLine(print,30000)
		postUpdate(Scanning, OFF)

This is the outcome:

2017-07-25 08:56:43.812 [INFO ] [eclipse.smarthome.model.script.debug] - scanimage: argument without option: `>/media/scan/scan_$(/bin/date +%Y%m%d_%H%M%S).tiff'; try scanimage --help

So the String looks good, but the redirect bit is not recognized as part of the command.

Leaving out the @@ separators:

leads to

2017-07-25 09:17:09.908 [INFO ] [eclipse.smarthome.model.script.debug] - scanimage: argument without option: `+%Y%m%d_%H%M%S).tiff'; try scanimage --help

but the free space between “date” and “+%Y%m%d_%H%M%S” is needed.

This for example starts scanning but ignores the redirect and prints the file to the CLI

`````var String print = “/usr/bin/sudo@@/usr/bin/scanimage@@–resolution=150@@–format=tiff>/media/scan/scan_$(/bin/date +%Y%m%d_%H%M%S).tiff”````

I really tried countless combination, can somebody help me?
Thanks a lot.

Honestly, your best bet will be to put the command into a shell script and call the shell script from executeCommandLine.

1 Like

I am not sure if it helps but here is my implementation of executeCommandLine that works like a charm

var url = ""
var outputFile = "/home/openhab/FrontDoor"+ now.toString ("HH-mm-ss_dd-MM-yyyy") +".jpg"
var cmd = "wget --output-document " + outputFile + " " + url