MATLAB and several command prompt commands

3 ビュー (過去 30 日間)
Egor Losev
Egor Losev 2023 年 1 月 12 日
コメント済み: Egor Losev 2023 年 1 月 15 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 1 月 12 日
Which operating system are you using?

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2023 年 1 月 12 日
編集済み: Jan 2023 年 1 月 12 日
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 件のコメント
Egor Losev
Egor Losev 2023 年 1 月 12 日
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.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2023 年 1 月 12 日
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 件のコメント
Egor Losev
Egor Losev 2023 年 1 月 15 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLicensing on Cloud Platforms についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by