Cygwin Shell scritp (.sh) in Matlab
7 views (last 30 days)
Show older comments
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
on 18 Jan 2013
I don't think we have enough information, as nothing you show appears to reference 1001_TEST.v
Answers (2)
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!
0 Comments
Christopher Lyman
on 18 Jan 2013
3 Comments
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.
See Also
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!