Execute Command

Post Reply
AndrewFriedman
Newbie
Posts: 7
Joined: Tue May 30, 2023 2:43 pm

Execute Command

Post 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
Attachments
Screen Shot 2023-11-09 at 10.31.30 AM.png
Screen Shot 2023-11-09 at 10.31.30 AM.png (88.38 KiB) Viewed 6893 times
Execute Command ScreenShots.zip
Here is my script
(213.45 KiB) Downloaded 133 times
User avatar
magnussandstrom
Advanced member
Posts: 320
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Execute Command

Post by magnussandstrom »

I would use the app 'Execute Command Friend' for this task.
AndrewFriedman
Newbie
Posts: 7
Joined: Tue May 30, 2023 2:43 pm

Re: Execute Command

Post by AndrewFriedman »

Is there any way to do this task with the execute command?
freddyp
Advanced member
Posts: 1000
Joined: Thu Feb 09, 2012 3:53 pm

Re: Execute Command

Post 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".
User avatar
magnussandstrom
Advanced member
Posts: 320
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Execute Command

Post 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 6815 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
AndrewFriedman
Newbie
Posts: 7
Joined: Tue May 30, 2023 2:43 pm

Re: Execute Command

Post 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?
Attachments
Screen Shot 2023-11-28 at 12.41.01 PM.png
Screen Shot 2023-11-28 at 12.41.01 PM.png (46.93 KiB) Viewed 6659 times
Screen Shot 2023-11-28 at 12.41.40 PM.png
Screen Shot 2023-11-28 at 12.41.40 PM.png (6.76 KiB) Viewed 6659 times
Mihail_Vereten
Newbie
Posts: 6
Joined: Wed Jul 29, 2020 9:27 am

Re: Execute Command

Post 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
Mihail_Vereten
Newbie
Posts: 6
Joined: Wed Jul 29, 2020 9:27 am

Re: Execute Command

Post 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'
bens
Advanced member
Posts: 251
Joined: Thu Mar 03, 2011 10:13 am

Re: Execute Command

Post 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.
rhd_ole
Member
Posts: 70
Joined: Mon Jan 24, 2022 5:36 pm

Re: Execute Command

Post 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 2801 times
Mihail_Vereten
Newbie
Posts: 6
Joined: Wed Jul 29, 2020 9:27 am

Re: Execute Command

Post 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
Post Reply