Program to generate buttons for sequence of commands

Discussion in 'Perl Misc' started by Raghuramaiah Gompa, Feb 9, 2006.

  1. 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?
     
    Raghuramaiah Gompa, Feb 9, 2006
    #1
    1. Advertising

  2. Raghuramaiah Gompa

    Paul Lalli Guest

    Raghuramaiah Gompa wrote:
    > 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
     
    Paul Lalli, Feb 9, 2006
    #2
    1. Advertising

  3. Raghuramaiah Gompa

    zentara Guest

    On Thu, 9 Feb 2006 14:57:49 +0000 (UTC),
    (Raghuramaiah Gompa) wrote:

    >
    >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__


    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
     
    zentara, Feb 10, 2006
    #3
  4. 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

    In article <>,
    zentara <> wrote:
    >On Thu, 9 Feb 2006 14:57:49 +0000 (UTC),
    >
    >(Raghuramaiah Gompa) wrote:
    >
    >>
    >>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__
    >
    >
    >--
    >I'm not really a human, but I play one on earth.
    >http://zentara.net/japh.html
     
    Raghuramaiah Gompa, Feb 10, 2006
    #4
  5. Raghuramaiah Gompa

    zentara Guest

    On Fri, 10 Feb 2006 19:22:34 +0000 (UTC),
    (Raghuramaiah Gompa) wrote:

    >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



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
     
    zentara, Feb 11, 2006
    #5
  6. In article <>,
    zentara <> wrote:
    >On Fri, 10 Feb 2006 19:22:34 +0000 (UTC),
    >
    >(Raghuramaiah Gompa) wrote:
    >
    >>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
    >


    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
     
    Raghuramaiah Gompa, Feb 11, 2006
    #6
  7. Raghuramaiah Gompa

    zentara Guest

    On Sat, 11 Feb 2006 15:57:32 +0000 (UTC),
    (Raghuramaiah Gompa) wrote:

    >In article <>,
    >zentara <> wrote:
    >>On Fri, 10 Feb 2006 19:22:34 +0000 (UTC),
    >>
    >>(Raghuramaiah Gompa) wrote:
    >>
    >>>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
    >>

    >
    >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. :)



    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
     
    zentara, Feb 11, 2006
    #7
  8. Thank you so much for your kind help and encouragement.
    I will follow your suggestions. .. Raghu

    In article <>,
    zentara <> wrote:
    >
    >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. :)
    >
    >
    >
    >--
    >I'm not really a human, but I play one on earth.
    >http://zentara.net/japh.html
     
    Raghuramaiah Gompa, Feb 12, 2006
    #8
  9. >
    >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__
     
    Raghuramaiah Gompa, Feb 13, 2006
    #9
  10. Raghuramaiah Gompa

    Dr.Ruud Guest

    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)

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Feb 13, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anil
    Replies:
    2
    Views:
    476
    Srinivasan Venkataramanan
    Sep 9, 2005
  2. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,973
    Thomas Stegen
    Jun 28, 2003
  3. Tim Stanka
    Replies:
    1
    Views:
    804
    Jeff Epler
    Aug 2, 2004
  4. stef mientki
    Replies:
    13
    Views:
    644
    stef mientki
    Oct 20, 2007
  5. Mauricio Rosales

    Generate Gridview commands from Code

    Mauricio Rosales, Oct 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    122
    Mauricio Rosales
    Oct 29, 2005
Loading...

Share This Page