0
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ As nobody has commented so far, I assume I dont't make an obvious mistake. Is this a bug? $\endgroup$
    – murphy
    Commented Aug 6, 2015 at 10:39
  • $\begingroup$ There is no comment because GUIKit not developed and not many folks are familiar with it. Sometimes related questions are answered due to the fact that the problem is in fact a Java one. $\endgroup$
    – Kuba
    Commented Aug 6, 2015 at 14:53
  • $\begingroup$ Is there any reason you are using GUIKit instead of for instance CreateDialog? $\endgroup$
    – Karsten7
    Commented Aug 6, 2015 at 17:14
  • $\begingroup$ No particular reason. Is CreateDialog intended/suitable for complex GUIs? $\endgroup$
    – murphy
    Commented Aug 6, 2015 at 19:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.