MATLAB and several command prompt commands

6 vues (au cours des 30 derniers jours)
Egor Losev
Egor Losev le 12 Jan 2023
Commenté : Egor Losev le 15 Jan 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.
  1 commentaire
Walter Roberson
Walter Roberson le 12 Jan 2023
Which operating system are you using?

Connectez-vous pour commenter.

Réponses (2)

Jan
Jan le 12 Jan 2023
Modifié(e) : Jan le 12 Jan 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 commentaire
Egor Losev
Egor Losev le 12 Jan 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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 12 Jan 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 commentaire
Egor Losev
Egor Losev le 15 Jan 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Licensing on Cloud Platforms dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by