I am working on a GUI project where I need to pipe a string I constructed in Mathematica into an external program. For example
s="This
is a
string.";
StandardForm[s]>>"!cat";
which prints as expected
This
is a
string.
into the terminal. However, if try to do the same from within the GUI, (in this case triggered by a button click)
Needs["GUIKit`"];
GUIRun[
Widget["Button",{
BindEvent["action",Script[
s="This
is a
string.";
StandardForm[s]>>"!cat";
]]}]]
the following shows up in the terminal:
"This\nis a\nstring."
which is the InputForm
of s
. Clearly this is a problem if the external program is not cat
and expects properly formatted input.
What is happening here?
I am running Mathematica 10.1 on Ubuntu 14.04 (64 bit).
Update:
I found a workaround by calling a wrapper function which was defined in Global
.
Needs["GUIKit`"];
PipeIt[inp_,com_]:=Block[{},StandardForm[inp]>>"!"<>com];
GUIRun[
Widget["Button",{
BindEvent["action",Script[
s="This
is a
string.";
PipeIt[s,"cat"];
]]}],
IncludedScriptContexts -> "Global`"]
But I still don't understand what causes the problem.
GUIKit
instead of for instanceCreateDialog
? $\endgroup$CreateDialog
intended/suitable for complex GUIs? $\endgroup$