필터 지우기
필터 지우기

Control Cygwin through Matlab script

조회 수: 9 (최근 30일)
Paschalis Garouniatis
Paschalis Garouniatis 2016년 5월 12일
댓글: Paschalis Garouniatis 2016년 5월 22일
Hello, I would consider myself as a rookie matlab user. I have installed Cygwin64 on my computer and use it to process .env files. Instead of processing one by one each .env file I want to create a matlab script which will guide Cygwin64 to the specified directory and process each .env file. How can I create this script? Thanks in advance!
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 5월 12일
This confuses me a bit, as cygwin64 provides a shell programming language; you would need a script written in the shell language. Also, env files are associated with environment variables, and it is not common to need to process multiple environment variable files?
Paschalis Garouniatis
Paschalis Garouniatis 2016년 5월 12일
Hello Walter thanks for the reply. I think I didn't describe correctly my situation. I use Cygwin64 to call an executable and process a specific file (the .env extension maybe was unnecessary info). I thought it would be possible to create a script which would do the following repeatedly: 1)cd (directory) 2)call executable and process a specific file 3)cd (other directory) 4)call executable and process another specific file Those I have to do by myself in every directory and my aim is to create a script which will contain all directories and commands that I need to be executed. That way I will execute through the script all the commands instead of executing every single one. I really hope this was helpful. Also you might need to know that my OS is Windows 10.

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 12일
The easiest way to handle this is at the shell level, rather than at the MATLAB level.
Create a file that has pairs of items on each line. The first thing on the line should be the directory name, using forward slashes instead of backslashes. If there are any spaces in the directory name, proceed them with spaces. The second thing on the line should be the file name, converted the same way. For illustration I will call this file InputSpecs . For example,
C:/Users/Pas/Documents\ And\ Files/Project1 dataset\ 5a.env
C:/Users/Pas/Documents\ And\ Files/Project7 20150830_second.env
Then prepare a second file, that looks like
while read dirname filename; do cd "$dirname"; COMMANDHERE < "$filename"; done
where COMMANDHERE should be replaced by the name of the executable. If there is some other way to indicate that the file is input, then use that instead of the "<". For illustration I will call this file CommandScript. For example,
while read dirname filename; do cd "$dirname"; afnis -infile "$filename"; done
Then, to run all of those, you can
system("cygwin CommandScript < InputSpecs")
  댓글 수: 2
Paschalis Garouniatis
Paschalis Garouniatis 2016년 5월 13일
Thanks a lot for your help Walter. I will give it a try.
Paschalis Garouniatis
Paschalis Garouniatis 2016년 5월 22일
Hello Walter. You were right about handling it at the shell level. I finally got up and running. Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by