Pass file name as a string through command line into Maple - command-line

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

Related

Exiftool: Want to output to one text file using -w command

I'm currently trying to use exiftool on Windows command prompt to read meta data from multiple files, then output to a single text file.
The exact command I last tried looked like this:
exiftool.exe -FileName -GPSPosition -CreateDate -d "%m:%d:%Y %H:%M:%S" -c "%d° %d' %.2f"\" -charset UTF-8 -ext jpg -w _Coordinate_Date.txt S:\Nick\Test\
When I run this, I get 7 individual text files with the content for one corresponding file in each of them. However, I simply want to output all of it to one single text file. Any help is greatly appreciated
The -w (textout) option can only be used to write multiple files. It is not meant to be used to output to a single file. As per the docs on -w:
It is not possible to specify a simple filename as an argument -- creating a single output file from multiple source files is typically done by shell redirection
Which is what you're doing with the >> ./output.txt part of your command. The -w _Coordinate_Date.txt isn't doing anything and I would think throw an Invalid TAG name: "w _Coordinate_Date.txt" error if quoted together like that as it gets treated as a single arugment. The -w option requires two arguments, the -w and either an extension or a format string.
I actually figured it out, if you wrap the entire -w _Coordinate_Date.txt command in quotations and append it to a file, you can throw all of the output into one text file.
i.e. "-w _Coordinate_Date.txt >> ./output.txt"

how to make cygwin tar output proper unicode letters instead of shashed values?

I have a *.tar.gz file that have inside occasionally some names with non ascii letters.
for example when tar encounter a file containing word: naïve it outputs: na\303\257ve
Is there any swich, or tool to convert these slashed values to a proper letter ?
http://www.gnu.org/software/tar/manual/tar.html
By default GNU tar attempts to unquote each file or member name, replacing escape sequences according to the following table: ...
This default behavior is controlled by the following command line
option:
--unquote
Enable unquoting input file or member names (default).
--no-unquote
Disable unquoting input file or member names.
In other words, see if "--no-unquote" is an option for your version of Cygwin.
PS:
Which version of Cygwin tar are you using?

Powershell Invoke-Expression mangling command

I am trying to invoke a command from a powershell script. The command works fine when run from a normal command line. Here is the full command (sorry, it's long, but if I truncate it I'm afraid I might leave out something significant.)
C:\Users\Dave.Work\Desktop\wix36-binaries\candle.exe C:\Users\Dave.Work\Developer\MapCreator\install\win\product.wxs -arch x64 -dPlatform=x64 -dProductVersion=0.9.1.0 -dKarteReleaseBinDir=C:\Users\Dave.Work\Developer\MapCreator\karte-build-release\release -out C:\Users\Dave.Work\Developer\MapCreator\install\win\obj\
If I invoke this exact same command using Invoke-Expression, it fails. It gives an error from the executable (candle.exe), but since it works fine from the command line, the problem is clearly that powershell is mangling the string somehow. Here is my call:
Invoke-Expression 'C:\Users\Dave.Work\Desktop\wix36-binaries\candle.exe C:\Users\Dave.Work\Developer\MapCreator\install\win\product.wxs -arch x64 -dPlatform=x64 -dProductVersion=0.9.1.0 -dKarteReleaseBinDir=C:\Users\Dave.Work\Developer\MapCreator\karte-build-release\release -out C:\Users\Dave.Work\Developer\MapCreator\install\win\obj\'
This results in the following error from candle.exe:
candle.exe : error CNDL0103 : The system cannot find the file '.9.1.0' with type 'Source'.
Somehow the numeric version number is getting mangled? Again, it works fine from a command line.
How to I pass this command to Powershell?
[NOTE] Ultimately, this command is generated from variables, i.e. the actual command will be something like:
$WixDir\candle.exe $ScriptDir\product.wxs -arch $Platform -dPlatform=$Platform -dProductVersion=$ProductVersion -dKarteReleaseBinDir=$KarteReleaseBinDir -out $ScriptDir\obj\
I'm using Invoke-Expression because I was having major problems expanding the variables using, for example, the call operator. But I can't get it to work even without the variable expansion. Thus, if the solution is to escape certain parts of the command string, I would need to also know how to apply those escapes to variables.
Try "-dProductVersion=0.9.1.0" enclosed with " or with '. My Get-Arg utility shows that the original command is parsed so that -dProductVersion=0 and .9.1.0 are different arguments.
Just in case, my Get-Arg.exe is (C#):
using System;
class GetArg
{
static void Main(string[] args)
{
foreach(string s in args)
{
Console.WriteLine(s);
}
}
}
It is useful for checking such cases.
There is even simpler illustration. This code
function Get-Argument {
$args
}
Get-Argument -dProductVersion=0.9.1.0
gets this output:
-dProductVersion=0
.9.1.0
That is PowerShell treats such a command as having two arguments.
Explanation
In PowerShell 2 0 Language Specification we can see for parameters
parameter-char:
Any Unicode character except
{ } ( ) ; , | & . [
colon
whitespace
new-line-character
Note: '=' is included, '.' is excluded. In our case we have
-dProductVersion=0.9.1.0
According to the specification all characters before '.' are valid parameter
characters. So we get, the first result argument is -dProductVersion=0
Then parser chokes at '.'. Technically, it looks like we do something against
the rules including '.' into the argument that starts with '-'. That is why we
should enclose the whole argument with ' or ".
This is probably true for the other excluded characters as well.

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

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

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.