Convert the contents of C:\WINDOWSSYSTEM32\cmc into a text file and open in Matlab

4 visualizaciones (últimos 30 días)
Hi all. How to Convert the contents of C:\WINDOWSSYSTEM32\cmc to a text file and open this text file in matlab?

Respuestas (2)

Steven Lord
Steven Lord el 11 de Sept. de 2023
I'm guessing your actual question is not about decompiling one of the executables included with Microsoft Windows into its source file or a text representation of the binary executable file. I suspect you want to run some code using the system function in MATLAB and work in MATLAB with whatever that code would print to the system command prompt. If that's the case, call the system function with two outputs and work with the contents of the second of those outputs.
As an example, call the system's date function and convert it into a datetime array. Compare with the output of the datetime function in MATLAB.
Note that this code is being run on a Linux machine, so I'm using the Linux date function. For Windows I believe you'd want to run 'date /T' to only display the current date setting and you'd need to change the value of the InputFormat input to the datetime call that creates dt2.
dt1 = datetime('now', 'TimeZone', 'UTC')
dt1 = datetime
11-Sep-2023 17:48:11
[status, output] = system('date')
status = 0
output =
'Mon Sep 11 17:48:11 UTC 2023 '
output = replace(output, newline, '') % Remove the extra newline
output = 'Mon Sep 11 17:48:11 UTC 2023'
dt2 = datetime(output, 'InputFormat', 'eee MMM dd HH:mm:ss z yyyy', 'TimeZone', 'UTC')
dt2 = datetime
11-Sep-2023 17:48:11
[dt1; dt2]
ans = 2×1 datetime array
11-Sep-2023 17:48:11 11-Sep-2023 17:48:11
  3 comentarios
roborrr
roborrr el 12 de Sept. de 2023
Editada: roborrr el 12 de Sept. de 2023
Thanks for answers.
I run the Fortran 77 executable file from MATLAB and in the cmc window I get the result shown in the figure below. where "AA" (=1) and "BB" (=2) are the names of the input data, "A" is the name of the output 3X3 matrix, I am trying to create variables in Matlab such that their names match the names that are visible in the window, and their the values coincided with the values that are visible under these names.
Since Fortran 77 does not have a variable name manager, I tried to artificially create variables from a text file in Matlab.
Is it possible to achieve my intentions in this way, or is there another method to create variables in matlab from cmc message?
Steven Lord
Steven Lord el 13 de Sept. de 2023
Are you running the Fortran 77 executable using the system command? If so call system with two outputs (as I did in the example above) and parse the second output (much like I did to convert it into a form the datetime function could handle.) Using an approximation to the data you showed:
t = char(' AA', ...
'1', ...
' BB', ...
'2', ...
'A', ...
' 0.50 0.50 0.50', ...
' 0.50 0.50 0.50', ...
' 0.50 0.50 0.50')
t = 8×24 char array
' AA ' '1 ' ' BB ' '2 ' 'A ' ' 0.50 0.50 0.50' ' 0.50 0.50 0.50' ' 0.50 0.50 0.50'
if I know the matrix starts on row 6 of the data:
data = str2num(t(6:end, :), Evaluation='restricted')
data = 3×3
0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000
Using the Evaluation option requires release R2022a or later, so you may not be able to use it if you're using an older release, but it can be safer (avoiding some "Bobby Tables" scenarios.)

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 12 de Sept. de 2023
cmd.exe is the Windows command shell, which absolutely will not contain anything pertaining to the fortran program you are running.
You have a few different options:
  • use MATLAB's system() to run the fortran executable and examine the second output. In practice you might need to set up some environment variables so that the executable can find its run-time libraries. Getting the environment variables right can be a bit of a nuisance but is not usually too hard
  • use the .NET interface System.Diagnostic.Process in MATLAB to run the fortran executable. This is more flexible than using system -- for example you can ask to read one line of output at a time. You will probably still need to set up environment variables correctly so the executable can find its run-time libraries
  • if the proper interface is constructed, then fortran functions can be called directly from MATLAB, including passing variables back and forth. This possibility takes the most set-up work, and would not typically be done for "small" programs -- more for "libraries"
  2 comentarios
Walter Roberson
Walter Roberson el 13 de Sept. de 2023
Movida: Walter Roberson el 13 de Sept. de 2023
If you use system() then the second output will be a character vector with embedded newlines. You can use text processing to process the character vector.
You might want to use code similar to
%break at lines that start with an identifier
parts = regexp(OUTPUT, '^\s*(?=[A-Za-z]', 'split');
%remove leading and trailing space on every line
parts = regexprep(parts, {'^\s+', '\s+$'}, '', 'lineanchors');
%remove empty areas
parts(cellfun(@isempty, parts)) = [];
parts will now be a cell array of character vector. Each section of parts should now begin with an alphabetic character, and all leading and trailing spaces on lines will have been removed. Any line that contained only whitespace will have been removed.
To the level of validation and pre-processing done so far, there is no guarantee that each section of parts will have only a single variable on the first line (and nothing else), or that the lines after that will contain matrices of numbers.
You can pick out the first word by using cellfun to textscan with format '%s' and count 1. You can attempt to pick out the numeric parts by using cellfun to textscan with format '' and 'HeaderLines', 1 .
Walter Roberson
Walter Roberson el 13 de Sept. de 2023
However, please read http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval for information about why we strongly recommend against creating variable names dynamically.
It would be better if you were to use dynamic field names in a struct.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by