clarification on dos command

given the statements
if (exist([current_folder, '/', file_name], 'file') && exist([current_folder, '/', strip_comments_exe], 'file'))
cmd=['"', [current_folder, '/', strip_comments_exe], '" ', strip_comments_options, ' ', [current_folder, '/', file_name], ' ', strip_comments_output_option, ' ', num2str(i), 'a.h'];
where the variables represent the following:
  1. current_folder = pwd,
  2. strip_comments_exe = relative path to a .exe file
  3. strip_comments_options = '' (empty string not double quotes)
  4. strip_comments_output_option = '>'
  5. file_name= relative path to a C header file
what is the function below supposed to achieve?
dos(cmd,'-echo')

 採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 7 日

0 投票

It will run the strip-comments executable, reading in the C header file, and output the results to a file whose name starts with the number "i" followed by a literal "a" and an ".h" extension.
For example, it might read in MyHFile.h and output 147a.h if "i" had the value 147 .
The -echo option will show the command before it is executed, but that will be written into the output file.

7 件のコメント

Faris
Faris 2011 年 3 月 8 日
Where exactly does the output file get written to? I don't see it in the current_folder. I do however see the a.h files in another folder, temp_folder = 'c:/temp'
There are 4 nested if-conditions I am testing. The 4th one is getting skipped which tells me the source_format_exe file is not doing what it is supposed to do (create the a.fmt file??)
if (exist([current_folder, '/', file_name], 'file') && exist([current_folder, '/', strip_comments_exe], 'file'))
cmd=['"', [current_folder, '/', strip_comments_exe], '" ', strip_comments_options, ' ', [current_folder, '/', file_name], ' ', strip_comments_output_option, ' ', num2str(i), 'a.h'];
dos(cmd, '-echo');
if (exist([temp_folder, '/', num2str(i), 'a.h'], 'file') && exist([current_folder, '/', get_typedef_exe], 'file'))
cmd=['"', [current_folder, '/', get_typedef_exe], '" ', get_typedef_options, ' ', num2str(i), 'a.h', ' ', get_typedef_output_option, ' ', num2str(i), 'a.def'];
dos(cmd, '-echo');
if (exist([temp_folder, '/', num2str(i), 'a.def'], 'file') && exist([current_folder, '/', source_format_exe], 'file'))
cmd=['"', [current_folder, '/', source_format_exe], '" ', source_format_options, ' ', num2str(i), 'a.def', ' ', source_format_output_option, ' ', num2str(i), 'a.fmt'];
dos(cmd, '-echo');
if (exist([temp_folder, '/', num2str(i), 'a.fmt'], 'file'))
fp=fopen([temp_folder, '/', num2str(i), 'a.fmt'], 'r');
Walter Roberson
Walter Roberson 2011 年 3 月 8 日
If the *a.h file was not getting written to to temp_folder then the earlier parts of the code would not succeed.
Is the *a.def file being produced in the temp dir? If so then you could cd to the temp dir and manually invoke the command that got echoed and see what result you get.
Faris
Faris 2011 年 3 月 8 日
The *a.h and *a.def files are being produced in temp_folder but *a.fmt is not (hence the 4th if condition being skipped)
I'm not sure as to exactly who is responsible for writing the output files in temp_folder, the dos(cmd,'echo') func'n or the exe files that are being run.
I un-suppressed the output of the cmd variables and included below to see if this might help?
Output:
Processing ./include/typedefs.h...
cmd =
"C:\Users\Faris\Documents\MATLAB\PaddingGenerator/./generator/strpcmt.exe" C:\Users\Faris\Documents\MATLAB\PaddingGenerator/./include/typedefs.h > 1a.h
cmd =
"C:\Users\Faris\Documents\MATLAB\PaddingGenerator/./generator/makeheaders.exe" -h 1a.h > 1a.def
cmd =
"C:\Users\Faris\Documents\MATLAB\PaddingGenerator/./generator/indent.exe" -sob -bl -bli0 -di1 -bc -bls -nbad 1a.def -o 1a.fmt
Walter Roberson
Walter Roberson 2011 年 3 月 8 日
The fact that it is writing in the temp directory is almost certainly due to a cd() somewhere above what you showed.
For the commands above the last one, it is the operating system that is causing the file to be written. The '>' in the command means "write the non-error output to the file whose name follows". I note that the last command instead uses -o as a command-line switch in order to indicate where to write, which means it is under the control of that program.
I would go in to a dos CMD window, cd to the temp directory, and type in that last command, and see what messages are produced.
Faris
Faris 2011 年 3 月 8 日
You're right. Before the if statements I had a cd (temp_folder) statement. I tried running the last command in a CMD window like and it gave me a system error running indent.exe 'program can't start b/c libintl3.dll is missing'
btw indent.exe is represented by the source_format_exe variable
Walter Roberson
Walter Roberson 2011 年 3 月 8 日
libintl3.dll is a FSF (Free Software Foundation -- GNU) library for internationalization. Your utilities have either not been built properly or have not been installed properly. See for example the discussion <http://forums.devside.net/index.php?topic=335.0 here>
Faris
Faris 2011 年 3 月 8 日
Gotcha! The program indent.exe was a package I downloaded but it seems I forgot to download the dependencies file for it. After downloading and putting the dll's in the System32 folder I can now see the *a.fmt files in temp_folder!!! Thanks~!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDownloads についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by