Execute python command with string attached in exec=">: format

I have a working python skript on windows10 that i can execute on the windows machine like this:
python C:\openhab\scripts\biamp.py "RECALL 0 PRESET 1015"
the doublequotes are necasary as this does not work:
python C:\openhab\scripts\biamp.py 'RECALL 0 PRESET 1015'

now im trying to get that working as a item but nothing works:

Switch BiampAudio_DSP_OnOff "Biamp Audio DSP" <player> { exec=">[ON:C:\python27\python C:\openhab\scripts\biamp.py 'RECALL 0 PRESET 1015']"}

The code above is with the full path to python installation but it seams strange to me with the ON:C: anyhow.

Switch BiampAudio_DSP_OnOff "Biamp Audio DSP" <player> { exec=">[ON:python@@C:\openhab\scripts\biamp.py 'RECALL 0 PRESET 1015']"}

This code above is not working as well and im not sure how wo get the doublequotes around the string 'RECALL 0 PRESET 1015' inside the exec=" " as this does not work as well:

{ exec='>[ON:python@@C:\openhab\scripts\biamp.py@@"RECALL 0 PRESET 1015"]'}

I tried all kinds of @@ replacements none works.

Is it possible to pass strings somehow?

One option would be to create a small script. e.g. biamp_recall.cmd that executes the entire commandline and have that script executed from the exec binding.

I’ve had some success using xxx.bat files in the scripts folder as intermediaries.

i have over 80 commands to build… no i will not make a replacement.

Things I notice:

  1. You are using the Exec 1 binding instead of the Exec 2 binding. The 2 binding has more capabilities and is more flexible.

  2. \ is an escape character. So \p is treated as one single character instead of two. So you need to escape the escapes. You also need to escape the :. For example, C\:\\python27\python C\:\\openhab\\scripts\\biamp.py

  3. You say that you need to use double quotes in the arguments you pass. In that case, just escape the double quotes as well. biamp.py \"RECALL 0 PRESET 1015\".

  4. As you notice, you might need to replace the spaces with @@. But it would be all of the spaces, not just the ones you indicated.

  5. You may need to supply the full path to the python command.

Yes, if you use the Exec2 binding. I don’t believe there is a way to do so with Exec 1. With the Exec2 binding, you have an input Channel that you can use to pass arguments to the script. Sending a command to an Item linked to that Channel will also run the script.

Is this because you can’t pass a String? If so then I strongly recommend using the Exec2 binding.

Is it possible to use Exec2 in openHAB 1?

No but since you did not mention which version of OH you are using and OH 1 development ended almost three years ago it seemed safe to assume that you would be running OH 2.

If you are on OH 1 I’m afraid you will find our ability to assist you to be quite limited. OH skills tend to be fungible. You use them or your lose them. Most of the people on this forum have not used OH 1 in years.

The same goes for bindings. The Exec2 binding has been out for over two years so the number of people who can really help beyond the basics already mentioned in this thread will be very limited as well.

An example snippet from an OH1 on Windows rule of mine.
Passes strings but uses the exec action in a rule.

// strings with escapes for windows paths
val String snapBIN = "C:\\openhab\\configurations\\scripts\\delfile.bat "
...
// calls e.g. delfile.bat C:\openhab\webapps\media\  channel09.jpg
results = executeCommandLine(snapBIN + snapDIR + " " + "channel" + Camera + ".jpg", 10000)

Thanks for all the help here. I misslead you guys by assuming that exec binding v1.9 is from openHAB1 what is not the case.
What helped is to not copy the path from windows cmd window but write ist as linux path with frontslash instead of backslash.
So actualy a easy thing. Took me several hours to work out. now it works.
this is the working command:
{ exec='>[*:python C:/openhab/conf/scripts/biamp.py "RECALL 0 PRESET 1001"]'}

for anybody searching how to interact with a biamp here is the skript its running:

#!/usr/bin/env python2

import socket
import os
import sys

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

sock.connect(('<insert_your_biamp_IP>', 23))
count = 1
while True:
	data = sock.recv(1)
	if data == b'\n':
		if count == 0:
			break
		count -= 1

sock.send('{}\r\n'.format(sys.argv[1]).encode('utf-8'))

response = ''
count = 1
while True:
	data = sock.recv(1)
	if data == b'\n':
		if count == 0:
			break
		count -= 1
	response += data

print(response)