MATLAB and several command prompt commands

6 visualizaciones (últimos 30 días)
Egor Losev
Egor Losev el 12 de En. de 2023
Comentada: Egor Losev el 15 de En. de 2023
Hello,
I have a device which I want to transfer files from through tftp. To do this I'm opening a command prompt and writing
tftp -i 10.0.0.22 get dmafiles-0
This begins the transfer. In total I need to transfer files 0-7.
I'm trying to make MATLAB run these commands for me without locking itself into busy mode.
I can do this if I create a function file with this command and use batch(function) to run this script:
ch = 0:7;
for i=1:length(ch)
command = sprintf('tftp -i 192.168.178.100 get dmafiles-%d', ch(i));
system(command)
end
This will offload the transfer to a different worker and not lock the main MATLAB window. However, this will transfer the files in a serial manner, one after the other. If I open several command prompts, I can transfer several files in parallel.
The issue is that I don't know how to offload each transfer onto a different MATLAB worker, which will then run the transfer of its respective file in a different cmd window.
Should I create 8 functions, each corresponding to its own file, and then batch all of them?
i.e. CH1, CH2, ..., CH8 and then batch(CH1), batch(CH2),..., batch(CH8)
Is there a better way?
In short, the issue is - open several command prompts and run a command in each. Works when done manualy, looking into how to implement in MATLAB.

Respuestas (2)

Jan
Jan el 12 de En. de 2023
Editada: Jan el 12 de En. de 2023
Try this under Windows:
for i = 0:7
command = sprintf('tftp -i 192.168.178.100 get dmafiles-%d && exit &', i);
% ^^^^^^^^^
system(command)
end
For Linux, use ; instead of &&.
  1 comentario
Egor Losev
Egor Losev el 12 de En. de 2023
I'm on windows.
This works, but it opens a cmd windows for each transfer process. Is there a way to transfer "silently"?
I have tried with the way I mentioned - doing batch in a for loop on 8 functions, and in each function there is a respective dmafiles-0-8 transfer. While not pretty, it does work in the background.
Your way is much neater, but opens 8 cmd windows.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 12 de En. de 2023
For Windows use System.Diagnostics.Process to create the transfer processes. You can invoke tftp directly without creating a command window, and you have control over the output stream.
  1 comentario
Egor Losev
Egor Losev el 15 de En. de 2023
Hello,
I'm trying the following:
for i = 0:7
Process = System.Diagnostics.Process();
command = sprintf('tftp -i 10.0.0.22 get dmafiles-%d', i);
Process.Start(command);
end
but it doesn't run, gives the following error:
Message: The system cannot find the file specified
Source: System
HelpLink: None

Iniciar sesión para comentar.

Categorías

Más información sobre Component-Based Modeling en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by