Program to generate buttons for sequence of commands

  • Thread starter Raghuramaiah Gompa
  • Start date
R

Raghuramaiah Gompa

I am new to perl. I am trying to write a code, runme.pl,
to
generate 16 buttons in 4 rows and 4 colums. Each button
will be associated with a sequence of commands. For
examle, after perl runme.pl test, when pressed the first
button, it should execute:

latex test.tex
dvips test.dvi
gview test.ps

(This is similar to TeXorg, if you know this. But
this will have a sequence of commands for each button
- not just one command.) Will you please help me get
started? Is this possible?
 
P

Paul Lalli

Raghuramaiah said:
I am new to perl. I am trying to write a code, runme.pl,
to
generate 16 buttons in 4 rows and 4 colums.

What kind of "buttons"? A GUI program on a standalone machine? Check
out the Tk module. A CGI program executed through a web browser?
Check out the CGI module.
Each button
will be associated with a sequence of commands. For
examle, after perl runme.pl test, when pressed the first
button, it should execute:

latex test.tex
dvips test.dvi
gview test.ps

command line arguments are stored in the variable @ARGV. Examine this
array to find out what command name was entered.
(This is similar to TeXorg, if you know this. But
this will have a sequence of commands for each button
- not just one command.) Will you please help me get
started? Is this possible?

You haven't given anywhere near enough information to know what "this"
is, let alone to know if it's possible.

Paul Lalli
 
Z

zentara

I am new to perl. I am trying to write a code, runme.pl,
to
generate 16 buttons in 4 rows and 4 colums. Each button
will be associated with a sequence of commands. For
examle, after perl runme.pl test, when pressed the first
button, it should execute:

latex test.tex
dvips test.dvi
gview test.ps

(This is similar to TeXorg, if you know this. But
this will have a sequence of commands for each button
- not just one command.) Will you please help me get
started? Is this possible?

Here is a basic demo, making it look even is up to you.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = tkinit;
#$mw->geometry("400x400");
my $rF = $mw->Frame( -width => 400 )->grid;

my %buttons;

my %commands = (
'1-1' => {text => 'Date', com =>'date', color=> 'pink'},
'1-2' => {text => 'ls', com => 'ls -la', color => 'lightblue'},
'1-3' => {text => 'Date', com =>'date', color=> 'pink'},
'1-4' => {text => 'top', com => 'ls -la', color => 'lightblue'},
'2-1' => {text => 'ps', com =>'date', color=> 'pink'},
'2-2' => {text => 'ls', com => 'ls -la', color => 'lightblue'},
'2-3' => {text => 'Dateyada', com =>'date', color=> 'pink'},
'2-4' => {text => 'lsfoobar', com => 'ls -la', color =>
'lightblue'},
'3-1' => {text => 'Datexxxx', com =>'date', color=> 'pink'},
'3-2' => {text => 'lsccc', com => 'ls -la', color =>
'lightblue'},
'3-3' => {text => 'Datebbbb', com =>'date', color=> 'pink'},
'3-4' => {text => 'lsnnn', com => 'ls -la', color =>
'lightblue'},
'4-1' => {text => 'Date777', com =>'date', color=> 'pink'},
'4-2' => {text => 'ls777', com => 'ls -la', color =>
'lightblue'},
'4-3' => {text => 'Dategggcom', com =>'date', color=> 'pink'},
'4-4' => {text => 'lsgggcom', com => 'ls -la', color =>
'lightblue'},
);


foreach my $key(keys %commands){
my ($i, $j) = split /-/,$key;
$buttons{$key}{'button'} = $rF->Button(
-text => $commands{$key}{'text'},
-background => $commands{$key}{'color'},
-command => sub{ &launch( $key ) }
)->grid(-row=>$i, -column=> $j );
}

MainLoop;

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
if(fork==0){ exec "xterm -hold -e $command" }

}
__END__
 
R

Raghuramaiah Gompa

Thank you so much for the code. This code generated the
button I wanted, however, the commands are not executed.
I am using Win Xp and the commands are for unix system.
What is it that I need to do to execute commands (such
as c:\texmf\miktex\bin\latex.exe test ) in
windows? .. Raghu (e-mail address removed)
 
Z

zentara

Thank you so much for the code. This code generated the
button I wanted, however, the commands are not executed.
I am using Win Xp and the commands are for unix system.
What is it that I need to do to execute commands (such
as c:\texmf\miktex\bin\latex.exe test ) in
windows? .. Raghu

Hi, I don't use windows, but there are a variety of ways to
launch win32 processes. See the following for ways to
do it, and the various considerations. For instance do
you want all the executed commands to be totally independent,
or do you want them all to die when your "button-selector-app"
is closed?

http://perlmonks.org?node_id=409996 there is an XP answer

http://perlmonks.org?node_id=522373

http://perlmonks.org?node_id=495209
 
R

Raghuramaiah Gompa

Hi, I don't use windows, but there are a variety of ways to
launch win32 processes. See the following for ways to
do it, and the various considerations. For instance do
you want all the executed commands to be totally independent,
or do you want them all to die when your "button-selector-app"
is closed?

http://perlmonks.org?node_id=409996 there is an XP answer

http://perlmonks.org?node_id=522373

http://perlmonks.org?node_id=495209

Thank you very much for all your help. I have gone
through all the links you have posted. They are beyond
me. I need to read more to understand them.

I want all the commands to be independent once executed
through the buttons. .. Raghu
 
Z

zentara

Thank you very much for all your help. I have gone
through all the links you have posted. They are beyond
me. I need to read more to understand them.

I want all the commands to be independent once executed
through the buttons. .. Raghu

Well I don't have windows to test, but I'll try to get
you going. In the script, where you go into the launch sub

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
if(fork==0){ exec "xterm -hold -e $command" }
}

you need to change the line
if(fork==0){ exec "xterm -hold -e $command" }

to something compatible with Windows.

The links I posted showed a few methods.
The easiest was using system with 1

system(1, $file_to_run );

So first, try changing the sub to

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
system( 1, $command }
}

and don't forget to change the 'com' assignments in the
%commands hash to your programs

'1-1' => {text => 'Latex test',
com => "c:\texmf\miktex\bin\latex.exe test",
color=> 'pink'},

etc
etc

#######################################################
If the system( 1, $cmd) dosn't work, you may have to use
the code from the other node

use Win32::process;
Win32::process::Create($ProcessObj,
"C:\winnt\notepad.exe",
"c:\sample.txt",
0,
DETACHED_PROCESS,
".") || die "cant find the application";


#########################################################

Finally, you may have to experiment a bit yourself.
Setup a simple script, to see if it launches your app.
Keep trying until you succeed. :)

Like:
##############################################
#!/usr/bin/perl
use warnings;
use strict;

system( 1, "c:\texmf\miktex\bin\latex.exe test");

<>; #wait for keypress to simulate continued operation
__END__


#############################################
You may find that you need something like
"c:\texmf\miktex\bin\latex.exe", "test",

due to the syntax peculiarities of the windows command line.

Good luck. :)
 
R

Raghuramaiah Gompa

Thank you so much for your kind help and encouragement.
I will follow your suggestions. .. Raghu
 
R

Raghuramaiah Gompa

Well I don't have windows to test, but I'll try to get
you going. In the script, where you go into the launch sub

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
if(fork==0){ exec "xterm -hold -e $command" }
}

you need to change the line
if(fork==0){ exec "xterm -hold -e $command" }

to something compatible with Windows.

The links I posted showed a few methods.
The easiest was using system with 1

system(1, $file_to_run );

So first, try changing the sub to

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
system( 1, $command }
}

and don't forget to change the 'com' assignments in the
%commands hash to your programs

'1-1' => {text => 'Latex test',
com => "c:\texmf\miktex\bin\latex.exe test",
color=> 'pink'},

etc
etc

#######################################################
If the system( 1, $cmd) dosn't work, you may have to use
the code from the other node

use Win32::process;
Win32::process::Create($ProcessObj,
"C:\winnt\notepad.exe",
"c:\sample.txt",
0,
DETACHED_PROCESS,
".") || die "cant find the application";


#########################################################

Finally, you may have to experiment a bit yourself.
Setup a simple script, to see if it launches your app.
Keep trying until you succeed. :)

Like:
##############################################
#!/usr/bin/perl
use warnings;
use strict;

system( 1, "c:\texmf\miktex\bin\latex.exe test");

<>; #wait for keypress to simulate continued operation
__END__


#############################################
You may find that you need something like
"c:\texmf\miktex\bin\latex.exe", "test",

due to the syntax peculiarities of the windows command line.

Good luck. :)

Once again, thank you very much for all your help. I
followed your advise and modified the code (see below -
button.pl) and it works. :)

But I want a little more than this. Each button should
contain a sequence of commands - not just one - that are
executed one after the other once the button is pressed.
Moreover, these commands should have a options from
button.pl argument. For example,
perl button.pl exam
should make the button 1 to execute
c:\texmf\miktex\bin\latex.exe exam.tex
c:\texmf\miktex\bin\yap.exe exam.dvi
....
....
(in the code below, I had the second command in the
second button - but I want to have this as a second
command in button one - I may have to have more
commands) How can I do this? .. Raghu

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = tkinit;
#$mw->geometry("400x400");
my $rF = $mw->Frame( -width => 400 )->grid;

my %buttons;

my %commands = (
'1-1' => {text => 'Latex ',
com => "c:\\texmf\\miktex\\bin\\latex.exe test",
color => 'pink'},
'1-2' => {text => 'yap',
com => "c:\\texmf\\miktex\\bin\\YAP.exe test",
color => 'lightblue'},
'1-3' => {text => 'Date', com =>'date', color=> 'pink'},
'1-4' => {text => 'top', com => 'ls -la', color
=> 'lightblue'},
'2-1' => {text => 'ps', com =>'date', color=> 'pink'},
'2-2' => {text => 'ls', com => 'ls -la', color
=> 'lightblue'},
'2-3' => {text => 'Dateyada', com =>'date',
color=> 'pink'},
'2-4' => {text => 'lsfoobar', com => 'ls -la', color =>
'lightblue'},
'3-1' => {text => 'Datexxxx', com =>'date',
color=> 'pink'},
'3-2' => {text => 'lsccc', com => 'ls -la', color =>
'lightblue'},
'3-3' => {text => 'Datebbbb', com =>'date',
color=> 'pink'},
'3-4' => {text => 'lsnnn', com => 'ls -la', color =>
'lightblue'},
'4-1' => {text => 'Date777', com =>'date',
color=> 'pink'},
'4-2' => {text => 'ls777', com => 'ls -la', color =>
'lightblue'},
'4-3' => {text => 'Dategggcom', com =>'date',
color=> 'pink'},
'4-4' => {text => 'lsgggcom', com => 'ls -la', color =>
'lightblue'},
);


foreach my $key(keys %commands){
my ($i, $j) = split /-/,$key;
$buttons{$key}{'button'} = $rF->Button(
-text => $commands{$key}{'text'},
-background => $commands{$key}{'color'},
-command => sub{ &launch( $key ) }
)->grid(-row=>$i, -column=> $j );
}

MainLoop;

sub launch {
my $key = shift;
my $command = $commands{$key}{'com'};
system( 1, $command );
}
__END__
 
D

Dr.Ruud

zentara schreef:
com => "c:\texmf\miktex\bin\latex.exe test",

You need to use single quotes, or they will be interpolated away.

com => q/c:\texmf\miktex\bin\latex.exe test/,


Also think about:

com => q/"c:\tex mf\mik tex\bin\latex.exe" test/,

(if you need to keep the "" because a space is embedded)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top