Running an external program from matlab linux

조회 수: 16 (최근 30일)
H R
H R 2017년 5월 28일
답변: Walter Roberson 2017년 5월 29일
Hello. I have an external program called Lin.exe. This program accept (read) one file and write to another file. In windows cmd this can be done as follows:
Lin.exe /f command_file.txt /o output_file.txt
In matlab windows, I can do this as:
yourCommand2 = strcat('"C:\Program Files (x86)\Lin.exe"',' /f',' "','command_file.txt, '"', ' /o', ' "','output_file.txt', '"');
system(yourCommand2);
There is a Linux version of this exe file that is ./Lin.exe. The file located in "/global/storage/./Lin.exe". I want to use use matlab in linux to be able to run this program using "unix" command. However, this only can run Lin.exe and does not read any file or write to any file given.
yourCommand=['"/global/storage/./Lin.exe"' ' /f ' '"/home/merakpeep.rwd"' ' /o ' '"test.txt"' ]
unix( yourCommand);
Can you please help on this?
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 5월 28일
Please try
! /global/storage/Lin.exe --?
and see if it gives output.
I would tend to suspect that a Linux version would use Linux option notation such as
cmd = '/global/storage/Lin.exe'
infile = '/home/merakpeep.rwd'
outfile = fullfile(pwd, 'test.txt')
YourCommand = sprintf('"%s" -f "%s" -o "%s"', cmd, infile, outfile)
unix(YourCommand)
Or perhaps with
YourCommand = sprintf('"%s" < "%s" > "%s"', cmd, infile, outfile)
H R
H R 2017년 5월 28일
Thank you Walter- It worked with the middle solution you have provided!

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 29일
Solution: program needed -f and -o flags in Linux instead of the /f and /o flags used in Windows

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by