passing filenames to a dos command

조회 수: 1 (최근 30일)
Prashant Verma
Prashant Verma 2023년 8월 17일
답변: Star Strider 2023년 8월 17일
I would like to use an DOS executable command. The command requires file input and output names.
I cannot figure out how to pass the filenames (which are characters in the Matlab program).
For example the executable I want to run is "dcmdjpeg", so I have tried using
dos('.\dcmdjpeg FileIn FileOut'), but offcourse once I have the apostrophes DOS does not know what FileIn and FIleOut are.
Ive also tried
eval('!.\dcmdjpeg' FilNamIn FilNamOut);
Again this doesnt work.
  댓글 수: 1
Prashant Verma
Prashant Verma 2023년 8월 17일
just to add a bit more info. If I try
status=dos(['.\dcmdjpeg ', FilNam1 FilNam2]);
then I get the error
$dcmtk: dcmdjpeg v3.6.0 2011-01-06 $
dcmdjpeg: Decode JPEG-compressed DICOM file
error: Missing parameter dcmfile-out

댓글을 달려면 로그인하십시오.

답변 (2개)

Kunal Kandhari
Kunal Kandhari 2023년 8월 17일
To pass the filenames to the dos command, you need to properly construct the command string to include the file names.
Here's how you can do it:
% Replace these with your actual file names
FileIn = 'input_file_name';
FileOut = 'output_file_name';
command = sprintf('.\\dcmdjpeg %s %s', FileIn, FileOut);
output = dos(command);
Where "sprintf" is a string formatter, you can read more about it here: sprintf
Hope it helps!

Star Strider
Star Strider 2023년 8월 17일
See if the system function will do what you want.
Also, see Run External Commands, Scripts, and Programs for a more extensive discussion.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by