Sending strings/promts to CMD which open an .exe

Tyring to send input to a cmd opened software:
They are just strings but if i ad another dos/system command it just starts a new cmd window. also adding & to each doesent work, i want so send the promts
dos('cd C:\Users\...\folder\ & build.exe')
system('cd C:\Users\...\folder\ & build.exe')
Bold are the strings i want so send but ist doesnt work it just stays till the underlined.
Perple_X version 6.9.1, source updated April 20, 2022.
NO is the default (blank) answer to all Y/N prompts
Enter a name for this project (the name will be used as the
root for all output file names) [default = my_project]:
NAME
The problem definition file will be named: NAME.dat
Enter thermodynamic data file name [default = hp02ver.dat]:
hp03ver.dat

2 comentarios

Use System.Diagnostics.Process
Alexander Balduin
Alexander Balduin el 30 de Mayo de 2022
Editada: Alexander Balduin el 30 de Mayo de 2022
Not sure how to handle the input, while there is no real documentaion on matlab, and in other Questions no real example...
i startet with this which results like in my first comment above (underlined)
build = System.Diagnostics.Process;
build.StartInfo.FileName = 'C:\Users\...\build.exe'
build.StartInfo.UseShellExecute = true;
build.Start(); % Start the process

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 2022
Try something like this:
% Prepare a command string for notepad to open the file.
commandString = sprintf('notepad "%s"', fullFileName);
% Call notepad as a separate process where the user can edit the file.
system(commandString);

4 comentarios

Alexander Balduin
Alexander Balduin el 30 de Mayo de 2022
Editada: Alexander Balduin el 30 de Mayo de 2022
doesn't work, while i need to give input parameter after starting the programm
i have to answer like 25 promts after starting it, this works to start the software
It does work to start the program and pass it some argument(s) on the command line that the program may be set up to accept. But some programs only have a limited set of command line arguments they recognize.
It sounds like after your program has started you want to give it 25 responses that don't depend on the whim of the user and are somehow specified in advance, like in a commands.txt file.
Sometimes you can do
programName << commands.txt
where commands.txt is filled up with your user responses, but it might depend on the actual program whether that works.
If that doesn't work, you can try java robot. A demo that you can adapt is attached.
Of course if the user wants to change anything, then you'll have to leave it interactive so they can change the inputs and all you can then is to launch the program for them, which my code does.
Alexander Balduin
Alexander Balduin el 30 de Mayo de 2022
Editada: Alexander Balduin el 30 de Mayo de 2022
thanks for the long reply! Maybe i should be more precise
i just wanted to create a script which should start a windows cmd which execute a compiled fortran script (its to complex to write it in matlab itself) (here the name is build.exe) where i change only some of the ~25 promts. Because i want to change the parameter like 400x where i read in a matrix in a loop where the values are changed.
The first method doesnt work sadly ....
the java robot doesnt help me too because if i have to do it again because something changed i can´t really reuse it because of the positioning of the mouse, also the its only like write something in the cmd like this:
Is ther an java robor to use keyboard inputs?
name_of_the_file
N
N
2
N
N
CH5C8O
CH3C80
N
1
1 250
200 400
N
11.3 48.1
Y
N
Y
Image Analyst
Image Analyst el 30 de Mayo de 2022
If you are using the window maximized so the widgets are in the same location all the time, then positioning the mouse may work.
There is a keypress option for java robot:
>> methods(mouse)
Methods for class java.awt.Robot:
Robot getClass keyRelease notify wait
createScreenCapture getPixelColor mouseMove notifyAll waitForIdle
delay hashCode mousePress setAutoDelay
equals isAutoWaitForIdle mouseRelease setAutoWaitForIdle
getAutoDelay keyPress mouseWheel toString

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 30 de Mayo de 2022

Comentada:

el 30 de Mayo de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by