Page 1 of 1

Execute Command

Posted: Tue Nov 14, 2023 5:20 pm
by AndrewFriedman
Hello,

So I have been trying to get the execute command to work for a little bit now and I can't seem to get it right. What I want to do is have my input files (PDF) gets put into the execute command that would trigger my script to run. My script will take the PDF files and string out parts of the text using OCR then lay it out on a json file. I was told to use arguments for my input and output folders ("%1" and "%3"). I also turned on my log and I can see that switch is executing the file path to my script (/Applications/MAMP/htdocs/Arg.py) along with the arguments but I still get output folders that don't have anything inside of them. I see that it's trying to execute something which is why I don't understand why I'm getting blank folders as the output. if anyone has any tips or tricks I can try to get this up and running that would be great!

Thank you

Re: Execute Command

Posted: Tue Nov 14, 2023 5:27 pm
by magnussandstrom
I would use the app 'Execute Command Friend' for this task.

Re: Execute Command

Posted: Tue Nov 14, 2023 5:50 pm
by AndrewFriedman
Is there any way to do this task with the execute command?

Re: Execute Command

Posted: Tue Nov 14, 2023 6:45 pm
by freddyp
There is a flaw in the setup of "Execute command". You have to consider that "Execute command" is like running a command on the command line (Terminal or Command prompt). If you were to type the path of the Python script the operating system would also complain. You have to run Python and the script is one of the parameters. Likewise in "Execute command" "Command or path" has to point to Python and the script path goes into the "Arguments".

Re: Execute Command

Posted: Wed Nov 15, 2023 9:44 am
by magnussandstrom
I found an old flow where I executed a Python script with Execute command, here are my settings:

python.png
python.png (38.04 KiB) Viewed 22023 times

Arguments on this case are:

Code: Select all

C:\Users\color\Documents\image-background-remove-tool\main.py -i "%1" -o "%3\[Job.NameProper].png" -m u2net

Re: Execute Command

Posted: Tue Nov 28, 2023 6:46 pm
by AndrewFriedman
Hello,

So I changed a few things but I don't think that my script is being run. I set up a test that should change the text in the output file when the script is running but I don't see any changes which is why I'm assuming that my script is not being run. Looking at the logs I noticed that there are quotation marks that are being added to the path that leads to my script. I don't know if this is a switch thing or what is happening. Is there something that I'm missing?

Re: Execute Command

Posted: Tue Dec 26, 2023 9:14 am
by Mihail_Vereten
Hi, can you please tell me where I can find detailed instructions on how to work with the execute command tool, I can't get the scripts to work even from the command line
magnussandstrom wrote: Wed Nov 15, 2023 9:44 am I found an old flow where I executed a Python script with Execute command, here are my settings:


python.png


Arguments on this case are:

Code: Select all

C:\Users\color\Documents\image-background-remove-tool\main.py -i "%1" -o "%3\[Job.NameProper].png" -m u2net

Re: Execute Command

Posted: Wed Jan 17, 2024 10:28 am
by Mihail_Vereten
Hi everyone, I can't figure out how the execute command tool works, specifically how the %1 %2 %3 arguments work.

For example I want to run a python script.
All json files included in execute command are converted to xml.
I use this script

Code: Select all

import sys
import os
import json
from dicttoxml import dicttoxml

# Конвертация из JSON в XML
def json_to_xml(input_file, output_folder):
    try:
        # Имя входного файла без расширения
        input_filename = os.path.splitext(os.path.basename(input_file))[0]

        # Путь к выходному XML файлу
        output_file_path = os.path.join(output_folder, f"{input_filename}.xml")

        # Чтение JSON из входного файла
        with open(input_file, 'r', encoding='utf-8') as f:
            json_data = json.load(f)

        # Преобразование JSON в XML без добавления типов данных каждого элемента
        xml_data = dicttoxml(json_data, custom_root='root', attr_type=False)

        # Запись результата в XML-файл
        with open(output_file_path, 'wb') as f:
            f.write(xml_data)

        print(f"Файл {input_filename}.json успешно преобразован в XML.")

    except Exception as e:
        print(f"Произошла ошибка при преобразовании {input_filename}.json:", str(e))

# Проверяем переданный путь к файлу и путь к выходной папке
if len(sys.argv) != 3:
    print("Использование: python j2x.py input_file output_folder")
else:
    input_file = sys.argv[1]
    output_folder = sys.argv[2]
    json_to_xml(input_file, output_folder)
command and path - C:/Users/enfocus/AppData/Local/Programs/Python/Python312/python.exe
arguments - C:/j2x.py %1 %2

I'm getting two errors

Code: Select all

Cannot send job: path 'C:/Users/enfocus/AppData/Roaming/Enfocus/Switch Server/temp/294/ScriptElement/2/117/ExecuteComandResult/1443735-1443736.json' does not exist

Code: Select all

Cannot complete sendToSingle() for 'C:/Users/enfocus/AppData/Roaming/Enfocus/Switch Server/temp/294/ScriptElement/2/117/ExecuteComandResult/1443735-1443736.json'

Re: Execute Command

Posted: Thu Jan 18, 2024 9:16 am
by bens
In the execute command app, what setting do you have for the "Output" property? According to the app documentation, this should be "Folder at path" if you want to output a new folder.

However it also looks like you're making a single file inside that folder, so perhaps "File at path" is a better fit. But then you'll have to edit the python script to create the file at %2 - currently it treats %2 as a folder and puts the file inside.

Re: Execute Command

Posted: Thu Jan 18, 2024 3:52 pm
by rhd_ole
Not sure if this well help but I use Python via execute command to do some data cleansing

I think like suggested, change your Output to File at Path, we also point to Python in the Command and then in the argument we put the path to the script

Here is my setup.

In the Arguments we have the path to the script in quotes, like this: "/Path to script/script.py" "%1" "%2"

Output : File at path
Screenshot 2024-01-18 at 8.50.36 AM.png
Screenshot 2024-01-18 at 8.50.36 AM.png (188.18 KiB) Viewed 18009 times

Re: Execute Command

Posted: Tue Feb 13, 2024 2:13 pm
by Mihail_Vereten
could you send your python script to understand the structure?
rhd_ole wrote: Thu Jan 18, 2024 3:52 pm Not sure if this well help but I use Python via execute command to do some data cleansing

I think like suggested, change your Output to File at Path, we also point to Python in the Command and then in the argument we put the path to the script

Here is my setup.

In the Arguments we have the path to the script in quotes, like this: "/Path to script/script.py" "%1" "%2"

Output : File at path

Screenshot 2024-01-18 at 8.50.36 AM.png