I would like to be able to pass a set of arguments from the web app to the worker and on to to the command.bat and the python app that runs to set options. I see in config.yaml that you can specify arguments but not sure how to set them from options and pull down menus from the parametrization in the viktor app. Code snippets would be much appreciated. Thank you!
Hi,
The config files will do command line input on your machine. When you do this manually, the input looks as follows:
C:\Users\yourname> ToolLauncher.exe inputfile --setting1 --setting2
this has three components:
- the executable name or path, in this case âToolLauncher.exeâ
- the arguments to the executable, in this case there are three:
inputfile
,--setting1
and--setting2
- and finally the working directory, in this case:
C:\Users\yourname
This will correspond to the following config file:
executables:
ToolLauncher:
path: 'ToolLauncher.exe'
arguments:
- 'inputfile'
- '--setting1'
- '--setting2'
workingDirectoryPath: 'C:\Users\yourname'
You can leave the workingDirectoryPath
empty if it does not matter from which folder the command is run, and you can also leave the arguments empty. The executable key ToolLauncher
can be any name, to be used in your app code to know which excecutable should be started in case you have multiple.
In your app code you will have the following:
from viktor.external.generic import GenericAnalysis
# Generate the input file(s)
files = [
('input1.txt', file1),
('input2.txt', file2)
]
# Run the analysis and obtain the output file.
generic_analysis = GenericAnalysis(files=files, executable_key="ToolLauncher", output_filenames=["output.txt"])
generic_analysis.execute(timeout=60)
output_file = generic_analysis.get_output_file("output.txt")
This tells the worker to:
- Create two files to the machine called
-
input1.txt
containing the string or bytesfile1
-
input2.txt
containingfile2
. - In case you specified a WorkingDirectoryPath, they will appear there (in this case the folder
C:\Users\yourname
) otherwise it will be a temporary folder somewhere on the machine
-
- Run the command
ToolLauncher.exe inputfile --setting1 --setting2
- Wait until the expected output file appears, called
output.txt
, at most 60 seconds and send it back
I hope this makes it more clear,
kind regards
Paulien
Yes, thank you. I already have all that working, but my question is: Is there any way to pass --setting1 and --setting2 programmatically from the viktor web app? In my case, they are not âconstantâ I need to send them from the web app.
No, unfortunately not. Sometimes I make the .bat file in my app code and send that to the worker as a full file. that is done in this example
May I ask what is the exact case? I have never needed that previously, so it would be interesting for us to know why you need variable arguments.
ok thanks. Basically, I am running energy analysis on a remote server and I need to tell it what results to send back. This takes the form of:
reports (e.g. âHVACSizingSummaryâ, âHVACSizingSummaryâ, âSystemSummaryâ)
tableNames (e.g. âZone Sensible Coolingâ, âZone Sensible Heatingâ, âTime Not Comfortable Based on Simple ASHRAE 55-2004â)
columnNames (e.g. âUser Design Loadâ, âUser Design Loadâ, âSummer or Winter Clothesâ)
unitsList = (e.g. âWâ or âhrâ)
As you said, a workaround would be to include all these in a structured file and have my script read it. No worries. Can be done.
If the number of possibilities is low and sending back all results is problematic, you could also consider specifying multiple keys under executables
I believe?
executables:
ToolLauncherNoArgs:
path: 'ToolLauncher.exe'
arguments:
workingDirectoryPath: 'C:\Users\yourname'
ToolLauncherArgX:
path: 'ToolLauncher.exe'
arguments:
- '--x'
workingDirectoryPath: 'C:\Users\yourname'
ToolLauncherArgY:
path: 'ToolLauncher.exe'
arguments:
- '--y'
workingDirectoryPath: 'C:\Users\yourname'
ToolLauncherArgXY:
path: 'ToolLauncher.exe'
arguments:
- '--x'
- '--y'
workingDirectoryPath: 'C:\Users\yourname'