Main Application Crashes during running a external process task

Discussion in 'Perl Misc' started by RBCS, Feb 14, 2006.

  1. RBCS

    RBCS Guest

    Hallo zusammen

    Hello I'v gota stupid questions

    When I insert this scriptsnipe to my main Application, this part runs very
    well but behind the main application crashes during this part is executing!

    It crashes also even I take out the RunAsUser (AdminMisc) part!

    Does someone has a idea?


    use strict;
    use warnings;

    my $Domain = "Workgroup";
    my $User = "testuser";
    my $Password = "testiman";
    my (@tasks);
    my $taski=0;

    #add some work!
    $tasks[$taski] = ( "notepad" );
    $taski++;
    $tasks[$taski] = ( "msiexec" );
    $taski++;
    $tasks[$taski] = ( "notepad" );

    #execute work
    my $ResultofRunas = RunAs->User($Domain, $User, $Password, @tasks); print
    "Result of Runas: $ResultofRunas"; #exit 0;

    package RunAs;

    use Win32::AdminMisc;
    use POE qw(Wheel::Run Filter::Reference);

    sub User{
    my( undef, $Domain, $User, $Password, @Process ) = @_;

    sub MAX_CONCURRENT_TASKS () { 3 }

    my $Result = Win32::AdminMisc::LogonAsUser( $Domain,
    $User,
    $Password,
    LOGON32_LOGON_INTERACTIVE );
    if( $Result )
    {
    my $LogonUser = Win32::AdminMisc::GetLogonName(); print "Successfuly
    started process as $LogonUser.\n"; $Result = POE::Session->create
    ( inline_states =>
    { _start => \&start_tasks,
    next_task => \&start_tasks,
    task_result => \&handle_task_result,
    task_done => \&handle_task_done,
    task_debug => \&handle_task_debug,
    }
    );
    if( $Result )
    {
    print "Successful! The new processes PID is $Result.\n";
    }
    else
    {
    my $err= Error();
    print"$err\n";
    }
    }
    else
    {
    my $err = Error();
    print"$err\n";
    }
    $poe_kernel->run();
    my $logofresult = Win32::AdminMisc::LogoffAsUser(); print "Logging
    off...\n";

    sub Error
    {
    return( Win32::FormatMessage( Win32::AdminMisc::GetError() ) );
    }
    }
    sub start_tasks {
    my $heap = $_[HEAP];
    while ( keys( %{ $heap->{task} } ) < MAX_CONCURRENT_TASKS ) {
    my $next_task = shift @Process;
    last unless defined $next_task;
    print "Starting task for $next_task...\n"; my $task =
    POE::Wheel::Run->new
    ( Program => ["$next_task", , ],
    StdoutFilter => POE::Filter::Reference->new(), StdoutEvent =>
    "task_result",
    StderrEvent => "task_debug",
    CloseEvent => "task_done",
    );
    $heap->{task}->{ $task->ID } = $task;
    }
    }
    }
    sub do_stuff {
    binmode(STDOUT); # Required for this to work on MSWin32 my $task
    = shift;
    my $filter = POE::Filter::Reference->new(); my %result =
    ( task => $task,
    status => "seems ok to me",
    );
    my $output = $filter->put( [ \%result ] ); print @$output;
    }
    }
    sub handle_task_result {
    my $result = $_[ARG0];
    print "Result for $result->{task}: $result->{status}\n";
    }
    }
    sub handle_task_debug {
    my $result = $_[ARG0];
    print "Debug: $result\n";
    }
    }
    sub handle_task_done {
    my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ]; delete
    $heap->{task}->{$task_id};
    $kernel->yield("next_task");
    }
    }
    RBCS, Feb 14, 2006
    #1
    1. Advertising

  2. RBCS <> wrote in
    news:p:

    > When I insert this scriptsnipe to my main Application, this part runs
    > very well but behind the main application crashes during this part is
    > executing!
    >
    > It crashes also even I take out the RunAsUser (AdminMisc) part!


    I would have tried to isolate what is related to the crash first. For
    example, do you get the same behavior without POE? (This is the easy way
    out for me, because I do not have POE installed, and I know nothing
    about it).

    >
    > Does someone has a idea?
    >
    >
    > use strict;
    > use warnings;
    >
    > my $Domain = "Workgroup";
    > my $User = "testuser";
    > my $Password = "testiman";
    > my (@tasks);
    > my $taski=0;
    >
    > #add some work!
    > $tasks[$taski] = ( "notepad" );
    > $taski++;
    > $tasks[$taski] = ( "msiexec" );
    > $taski++;
    > $tasks[$taski] = ( "notepad" );



    You can replace all of the above with:

    my @tasks = qw( notepad msiexec notepad );

    > #execute work
    > my $ResultofRunas = RunAs->User($Domain, $User, $Password, @tasks);
    > print "Result of Runas: $ResultofRunas"; #exit 0;


    Your style of shoving multiple statements per line is simply awful to
    read as well as the fact that you use inconsistent indenting with
    multiple closing braces at the same indent level. These factors make it
    unnecessarily hard to read your code.

    > sub User{
    > my( undef, $Domain, $User, $Password, @Process ) = @_;


    If you do not want to call the subs in RunAs as methods, then don't call
    them as methods (i.e. use RunAs::User).

    >
    > sub MAX_CONCURRENT_TASKS () { 3 }


    What is the point of this nested sub definition?

    Anyway, after installing POE, I get the following results:

    D:\Home\asu1\UseNet\clpmisc> perl -c synchk.pl
    Global symbol "@Process" requires explicit package name at synchk.pl
    line 74.
    Unmatched right curly bracket at synchk.pl line 87, at end of line
    syntax error at synchk.pl line 87, near "}"
    synchk.pl had compilation errors.

    Please post a short but complete script that compiles and runs with no
    warnings/errors.

    Please read the posting guidelines for this group.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 14, 2006
    #2
    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. Earl Eiland
    Replies:
    0
    Views:
    322
    Earl Eiland
    Mar 18, 2005
  2. Earl Eiland
    Replies:
    0
    Views:
    364
    Earl Eiland
    Mar 19, 2005
  3. teggy
    Replies:
    0
    Views:
    808
    teggy
    May 29, 2007
  4. Mike
    Replies:
    1
    Views:
    1,921
    GArlington
    May 12, 2008
  5. Mo
    Replies:
    0
    Views:
    131
Loading...

Share This Page