Cygwin Shell scritp (.sh) in Matlab

7 views (last 30 days)
Christopher Lyman
Christopher Lyman on 18 Jan 2013
I've been attempting to convert raw image data into a format which we can then run statistics by running Cygwin command as a shell script in Matlab.
The piece of script in question:
text_out = ['ecat2ana -frames -O=ecat2ana ' fconvert];
fin = [home_dir '!Incoming_PET\run_ecat2ana.sh'];
sh_script = fopen(fin,'w');
fprintf(sh_script,'%s',text_out);
fclose('all');
system(['C:\cygwin\bin\bash --login -c "/cygdrive/z/Hopkins-data/!Incoming_PET/run_ecat2ana.sh"']);
In which I'll get, "Error: file 1001_TEST.v does not exist"
Script Explanation:
text_out = a variable string of text that is required in Cygwin to convert the raw image data.
fin = the full directory to the shell script.
Background info:
I'm working in a Windows 7 environment on a Domain network. The data I'm attempting to work with is on a stand alone file server which is not on the domain.
I first copy the raw image data into a processing dir (/!Incoming_PET). I've noticed that the file permissions change for group and other when this occurs. Here's the copyfile script:
copyfile([PathName '\' FileName],[home_dir '!Incoming_PET\'],'f');
I've looked everywhere for a solution. If you have any ideas, I'm all ears.
  2 Comments
Walter Roberson
Walter Roberson on 18 Jan 2013
I don't think we have enough information, as nothing you show appears to reference 1001_TEST.v
Christopher Lyman
Christopher Lyman on 18 Jan 2013
"1001_TEST.v" is merely the arbitrary name of a raw image file I'm working with to try and fix this script. I left out parts of the script that do work such as declaring the home directory, using an uigetfile for selecting the raw image file which also sets the FileName and PathName variables, which are used later to return the converted results to the appropriate directory. Matlab actually crashes at this point in the script when I run it complete as there is no file to move.

Sign in to comment.

Answers (2)

Jason Ross
Jason Ross on 18 Jan 2013
I'm wondering if the exclamation point in the string is getting consumed somewhere along the way -- since you are shelling out of MATLAB into CMD, then starting the Cygwin bash command, it's highly possible that the !, / or \ is being gobbled up along the way as some sort of escape character or logical operator and you are ending up one character off. When I've needed to troubleshoot this kind of thing in the past, I've found the easiest way to do it is to build the string in parts, then concatenate it, then finally make the call. This allows fine-grained control, the ability to echo/print commands as you build them, and then the ability to make one part of the string have "\\" to make "\" while another part needs "\/" to escape the string and end up with a "/". Not to mention all the varied fun with the """ and "'" operators :)
I also tend to work up from the bottom, making sure the basic command works first in cygwin bash, then moving on up till you get to the highest level (in this case, the MATLAB call).
As for the directory permissions, you have at least two levels where there could be something getting translated incorrectly. Having the file server be off the domain means that you are likley having to re-authenticate, and then trying to translate that through cygwin which (IIRC) is attempting to map Windows ACLs to UNIX permissions may not get it "right".
Not knowing your requirements and restrictions, I'd examine if it was easier (or possible) to do the thing using a batch file (which works "for free" on Windows), or using something like Perl that can be a fairly easy port from shell, but has the benefit of being callable from MATLAB (perl()), and has a lot of built-in path handling logic to make it more easily portable if you need it to work on both Windows and Linux. In my personal experience, I've found getting the directory separators "right" can often drive one nuts, especially when the tool of choice can interpret them "mostly right".
Also, could you more easily get at the data using something like ftp or wget (I assume this utility is in cygwin) -- at least you will know which way the slashes should go!

Christopher Lyman
Christopher Lyman on 18 Jan 2013
Thank you for the quick response.
I guess some further information may help clarify the issue:
The script had worked previously before we transferred our data to this new server. The only change to the script was the drive letter indicating the server. This made me suspect that the error is occurring on the server side (which it still may be). Yet, I still am able to manually run the script in Cygwin even while the data is on the server. It is only when I run the script through Matlab that it doesn't work. Also, when I reverted back to our old domain area data this script now doesn't work. I am the administrator of the stand alone server and have administrative privileges on the domain. I've set permissions as read/write/execute for user/group/other on the server and yet when the file copies from one folder to the other the group and other permissions change to no permissions. I can't recall why we went with the "!" before the folder but it had something to do with how Cygwin reads this folder and again it had worked this way before. This is very curious.
Thank you for the advice and I'll look further into the options you mentioned.
  3 Comments
Christopher Lyman
Christopher Lyman on 18 Jan 2013
The server is a Windows server 2008. The processing computer is a windows 7 machine.
Jason Ross
Jason Ross on 22 Jan 2013
Well, that at least eliminates that as a problem!
If you have the previous machine around, I'd check the share permissions as well as the underlying filesystem permissions.

Sign in to comment.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!