Re: Inquiry about portable GUI and scripting

From: Tom Roberts <tjrob_at_fnal.gov>
Date: Mon, 22 Jan 2007 09:15:16 -0600


Thank you. I found a rather simple way to kill a task/process based on its name (which I know):

     #ifdef WIN32
                 // Some systems have taskkill, some have tskill, so
                 // do both and ignore any errors
                 gSystem->Exec("taskkill /f /im g4beamline.exe");
                 gSystem->Exec("tskill g4beamline");
     #else
                 // works on Linux and MacOSX
                 gSystem->Exec("killall g4beamline");
     #endif

This will kill all instances of "g4beamline" that the user has running, which is OK -- it avoids the complexity of figuring out the pid of the process (remember that Exec() is likely to return the pid of a shell).

But I found an insurmountable problem: In order to copy stdout into a TGTextView I need to use a TThread, but to use a TThread I need to compile the program, and I cannot expect my users to have a C++ compiler installed -- indeed, most won't. So I am stopping working on this using Root, and am switching to Java; I can expect Java runtime to be installed.

Thank you all for your assistance.

Tom Roberts

Bertrand Bellenot wrote:
> Hello Tom,
>
> 1) Here is one way to redirect stdout/stderr (as used in
> TSessionViewer):
>
> TString pathtmp = Form("%s/anyfile", gSystem->TempDirectory());
> // redirect stdout/stderr to temp file
> if (gSystem->RedirectOutput(pathtmp.Data(), opt) != 0) {
> Error("ShowStatus", "stdout/stderr redirection failed; skipping");
> }
> // execute command line
> gApplication->ProcessLine(cmd);
> // restore back stdout/stderr
> if (gSystem->RedirectOutput(0) != 0) {
> Error("ShowStatus", "stdout/stderr retore failed; skipping");
> }
> // if check box "clear view" is checked, clear text view
> if (fClearCheck->IsOn())
> fInfoTextView->Clear();
> // load (display) temp file in text view
> fInfoTextView->LoadFile(pathtmp.Data());
>
> 2) There is no simple solution...
> Plese take a look at the attached file (KillProcByName), it may help (it
> is pure Win32 code).
>
> 3) To hide the command prompt on Windows, please take a look at this
> page:
> http://root.cern.ch/root/HowtoWindows.html
>
>
> Cheers,
> Bertrand.
>
> -----Original Message-----
> From: owner-roottalk_at_pcroot.cern.ch
> [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Tom Roberts
> Sent: Monday, January 22, 2007 12:16 AM
> To: roottalk_at_pcroot.cern.ch
> Subject: Re: [ROOT] Inquiry about portable GUI and scripting
>
> I have spent an hour or two playing with this, and have a reasonable
> first attempt. It has a TGTextEntry to enter a command, a Run button,
> and uses a TThread to copy stdout of the command to a TGTextView -- that
> is most of what I need. Eventually I'll make it find my executable and
> setup its environment (what I need the portable scripting to do).
>
> Two limitations:
>
> 1) I would like to have a pipe both to stdin and from stdout of
> the command. TSystem::OpenPipe() cannot do that (indeed, the
> usual popen(3) cannot do it). I can work around this.
>
> 2) How do I kill the command (running from OpenPipe() or Exec())?
> This I absolutely need. On Linux and MacOS I know what to do;
> what do I do on Windows? My program must be compiled (ACLiC),
> and I am willing to use #ifdef WIN32, but don't know what to
> put there....
>
> And a question: Is there a way to suppress or hide the
> stdin/stdout/terminalWindow of Root? It is likely to confuse some
> users....
>
>
> Tom Roberts
>
>
Received on Mon Jan 22 2007 - 16:15:45 CET

This archive was generated by hypermail 2.2.0 : Mon Jan 22 2007 - 17:50:00 CET