I have trouble using mcc compiler in MATLAB (Error using ==> mcc The output directory does not exist) - matlab

I'm trying to build the .NET assembly file by executing this code in matlab2010b
workdir = 'C:\Users\H\Documents\Source Code\MatlabFiles';
outdir = fullfile(workdir, 'Output');
dnetdir = fullfile(workdir, 'dotnet');
%% Determine file names
mfile = fullfile(workdir, 'perform.m');
dnetdll = fullfile(dnetdir, 'dotnet.dll');
%% Create directories if needed
if (exist(outdir, 'dir') ~= 7)
mkdir(outdir);
end
if (exist(dnetdir, 'dir') ~= 7)
mkdir(dnetdir);
end
%% Build .NET Assembly
eval(['mcc -N -d ' dnetdir ' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ' mfile]);
I'm getting this error.
??? Error using ==> mcc
The output directory,
'C:\Users\H\Documents\Project\thesis\Source'
does not exist.
I'm pretty sure it's because of the space in the directory path "...\Source Code\...".
Because if I just use another path with no spaces it works perfectly fine.
Is there a way to make this work?
Thank you.

I think the actual problem occurs with your EVAL statement. You build a string to evaluate by concatenating strings like dnetdir and mfile, each of which will have a file path with a space in it. The resulting string you pass to EVAL will look like this:
mcc -N -d C:\Users\H\Documents\Source Code\MatlabFiles\dotnet -W ...
^--Look at that ugly space!
What you need to do is build your string so that there are apostrophes around these paths, like this:
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ''' mfile '''']);
Which will result in a string that looks like this:
mcc -N -d 'C:\Users\H\Documents\Source Code\MatlabFiles\dotnet' -W ...
And which will be evaluated properly now even with that nasty space in there.

I don't have any experience with mcc but some other functions may suffer from similar problems since most people are used to using the command mode (i.e. similar to the command prompt in DOS, Linux, Mac, ...). However, most functions are really functions such that you can use them in function mode and pass their arguments within parentheses.
You can also use mcc in function mode, as described in the help. That might look somewhat like:
mcc('-N', '-d', dnetdir, '-W', 'dotnet:dotnet,dotnetclass,0.0,private', '-T', 'link:lib', mfile);
That way you should not have to worry about escaping any character.

try changing the last line to:
eval(['mcc -N -d ''' dnetdir ''' -W ''dotnet:dotnet,' ...
'dotnetclass,0.0,private'' -T link:lib ' mfile]);
note the extra quotes around dnetdir

Related

Pass file name as a string through command line into Maple

I'm trying to use Maple function in external program using command-line interface. Data for function is to be passed through file. For demonstration of the problem I created two files: /home/user_name/test.mpl and /home/user_name/test_data.txt.
test.mpl ("cat" demonstrates use of Maple function):
#filename := "/home/user_name/test_data.txt":
print(filename):
i := parse(readline(filename)):
poly := parse(readline(filename)):
s := parse(readline(filename)):
print(cat(convert(poly+i,string), " ", s)):
test_data.txt :
1
x^2 * y + 1
"A string."
According to the manual, I can use something like this (but this example doesn't cover usage of two files, one as a code and another as an argument):
/usr/local/maple/bin/maple -c 'datafile:="/tmp/12345.data";' -c N:=1;
When I try
/path/to/maple -c 'filename:="/home/user_name/test_data.txt":' -q /home/user_name/test.mpl
I get the following error:
Error, incorrect syntax in parse: `/` unexpected (near 11th character of parsed string)
If I delete first / in filename string, I get the following output (before the errors related to readline):
/ home \
|-------------------| . txt
\user_name test_data/
It clearly demonstrates that file path is not parsed as a string (but probably as some kind of expression). Probably I should use some escape sequences, for Maple or for shell, but none of my attempts worked.
If I get file name inside test.mpl (uncommenting first line there and removing -c parameter), it works though, but that's not what I need.
How to pass file name as a string through command line (probably not with using -c)?
It works for me using commandline Maple on Linux, as say,
/path/to/maple -c 'filename:=\"/home/user_name/test_data.txt\":' -q /home/user_name/test.mpl

How can I ensure my autocompleted spaces are fed into my function properly?

I'm using zsh, and am trying to write a function to operate on a URL and a pathname:
function my-function
{
somecommand --url $1 $(readlink -f $2)
}
(to complicate things somewhat, the function actually uses sh syntax, as it is sourced from my ~/.zshrc using a trick like this). The readlink is there to expand symlinks and ensure directories such as . are evaluated correctly (the directory name is stored for later use by somecommand).
When I type a command from the command-line like this:
my-function http://example.org/example /tmp/myexampledirectory
... it works fine, even if I autocomplete the directory name. However, if the directory name contains spaces, zsh completes it like this:
my-function http://example.org/example /tmp/My\ Example\ Directory
For most "normal" commands (cp, mv, etc.) that never seems to cause a problem. However, in my case, somecommand sees $2 as only being /tmp/My - presumably the rest is seen as another argument.
How can I avoid this situation? I would prefer not to alter the standard zsh autocompletion, but rather find a way for my function to handle this.
The zsh completion system works very well here, and the solution is very simple, just put double-quotes around the readlink argument in the script:
somecommand --url $1 $(readlink -f "$2")
The point is that without quotes readlink removes backslashes which escape whitespaces. Compare three results:
1. Without backslashes and quotes readlink -f assumes that there are three different files/directories (with default path in current directory) and produces
$ readlink -f /tmp/My Example Directory
/tmp/My
/home/jimmij/Example
/home/jimmij/Directory
2. With escaping backslashes but without quotes readlink -f understands that there is only one directory, but removes backslashes from output, so that somecommand takes three separate arguments
$ readlink -f /tmp/My\ Example\ Directory
/tmp/My Example Directory
3. With backslashes and with double-quotes readlink -f gives the output with backslashes what is (most probably) expected by somecommand
$ readlink -f "/tmp/My\ Example\ Directory"
/tmp/My\ Example\ Directory
BTW, as a rule of thumb: if there are any problems with whitespaces in the shell-like scripts (bash, zsh, whatever) the first thing to play with is different quotation marks around variables.

Is it possible to edit the output of an Eclipse variable when making an External Tool?

I am trying to make an External Tool in Eclipse which requires several file names as inputs. However, I need to edit the output from the variable to exclude the file extension.
My arguments look as follows:
makeindex ${selected_resource_name}.nlo -s nomencl.ist -o ${selected_resource_name}.nls
The output from this compiles as follows:
makeindex filename.tex.nlo -s nomencl.ist -o filename.tex.nls
However, I would like to remove the .tex extensions, so the command compiles as
makeindex filename.nlo -s nomencl.ist -o filename.nls
Is this possible? And if so, how can I do this from within Eclipse?
From what i am seeing it looks like you are trying to replace '.tex' with '.nlo'. You could use substring to specify the name minus the last four characters (.tex). And do the rest as you were.
Example:
$new_name = substr(selected_resource_name, 0, -4);
makeindex ${new_name}.nlo -s nomencl.ist -o ${new_name}.nls
This should return your desired result.

sed command to extract from xml

I'm using my mac terminal to do a script, it basically does:
wget http://p2.edms-pr.ccomrcdn.com/player/player_dispatcher.html?section=radio&action=listen_live
This file returns an XML which I can save to txt or XML, I'm saving it as "url.xml"
<PlayerContent>
<ListenLiveInitialize>
<StreamInfo>
<stream id="4694" primary_location="rtmp://cp58082.live.edgefcs.net/live/COR_5103_OR#s5137?auth=daEaIcRcbb.afahbOdwbWdjdYcEdYaOaDdc-bn7nM7-4q-PN0X1_3nqDHom4EBvmEuwr&aifp=1234&CHANNELID=4694&CPROG=_&MARKET=PREMIERE&REQUESTOR=EDMS-PR&SERVER_NAME=p2.edms-pr.ccomrcdn.com&SITE_ID=13293&STATION_ID=EDMS-PR&MNM=_&TYPEOFPLAY=0" backup_location=""/>
</StreamInfo>
<JustPlayed/>
I want to used SED to return the AUTH code inside "primary_location". So basically I want to store
daEaIcRcbb.afahbOdwbWdjdYcEdYaOaDdc-bn7nM7-4q-PN0X1_3nqDHom4EBvmEuwr
on a variable.
I found this online but it doesn't seem to be working.
sed -n 's/.*\(auth=......................................... ...........................\).*/\1/p' url.xml
Try
sed -n 's|^<stream.*auth\=\(.*\)\&ai.*|\1|p' url.xml
which reads the file and matches the line up to the = before the auth code, stores everything from there up to the & in &ai as \1 which is then substituted for the whole pattern space.
You have a stray space () in the middle of your .s!
This is neater and will output auth= with the value (it looks like it's a string of alphanumerics with hyphens and underscores):
% grep -o 'auth=[[:alnum:]_-]\+' url.xml
You could even use it like so:
% eval $(grep -o 'auth=[[:alnum:]_-]\+' url.xml)
% echo ${auth}
daEaIcRcbb.afahbOdwbWdjdYcEdYaOaDdc-bn7nM7-4q-PN0X1_3nqDHom4EBvmEuwr
Works on OSX.

run Matlab in batch mode

It seems to me that there are two ways to run Matlab in batch mode:
the first one:
unset DISPLAY
matlab > matlab.out 2>&1 << EOF
plot(1:10)
print file
exit
EOF
The second one uses option "-r MATLAB_command":
matlab -nojvm -nosplash -r MyCommand
Are these two equivalent?
What does "<< EOF" and the last "EOF" mean in the first method?
Thanks and regards!
The first method simply redirects the standard output > matlab.out and the standard error 2>&1 to the file matlab.out.
Then it uses the heredoc way of passing input to MATLAB (this is not specific to MATLAB, it is a method of passing multiple lines as input to command line programs in general).
The syntax is << followed by an unique identifier, then your text, finally the unique id to finish.
You can try this on the shell:
cat << END
some
text
multiple lines
END
The second method of using the -r option starts MATLAB and execute the statement passed immediately. It could be some commands or the name of a script or function found on the path.
It is equivalent to doing something like:
python -c "print 'hello world'"
Refer to this page for a list of the other start options.