Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Can users on the web run program in background?

busakornbusakorn Posts: 20Member
Hello everyone.

What I want to do is, let the users click on the button and execute the script in background, plus I use the javascript function setTimeout to wait for 2 seconds and close the window after that, my script looks like,

#-----------------------------------------------------------------
#!/usr/bin/perl
print "content-type:text/html

";
print qq(








);
system "./test.pl &";
#--------------------------------------------------

and it turns out that the window remains open until the test.pl script finish running, in other word, it's not running in background at all.

Can anybody help me out here? Any advice would be very appreciated, thanks in advance.

Comments

  • bgibbybgibby Posts: 251Member
    Hi there,

    Try using the backticks (ie. `./test.pl &`;) as it's designed to execute and return a value (if any) as tho the script is being run from the server rather than the System call which needs an exit code from the program and doesn't receive one until it's finished.

    Also, might be a stupid thing to ask, are you running this on a Linux-based server or Windows-based?

    Cya
    Bradley q:)

    : Hello everyone.
    :
    : What I want to do is, let the users click on the button and execute the script in background, plus I use the javascript function setTimeout to wait for 2 seconds and close the window after that, my script looks like,
    :
    : #-----------------------------------------------------------------
    : #!/usr/bin/perl
    : print "content-type:text/html

    ";
    : print qq(
    :
    :
    :
    :
    :
    :
    :
    :
    : );
    : system "./test.pl &";
    : #--------------------------------------------------
    :
    : and it turns out that the window remains open until the test.pl script finish running, in other word, it's not running in background at all.
    :
    : Can anybody help me out here? Any advice would be very appreciated, thanks in advance.
    :

  • busakornbusakorn Posts: 20Member
    Hello again,

    I've tried it, and it's not working either, thanks anyway.
    And I'm running this on a Linux-based server but would like windows user
    to run the script.

    : Hi there,
    :
    : Try using the backticks (ie. `./test.pl &`;) as it's designed to execute and return a value (if any) as tho the script is being run from the server rather than the System call which needs an exit code from the program and doesn't receive one until it's finished.
    :
    : Also, might be a stupid thing to ask, are you running this on a Linux-based server or Windows-based?
    :
    : Cya
    : Bradley q:)
    :
    : : Hello everyone.
    : :
    : : What I want to do is, let the users click on the button and execute the script in background, plus I use the javascript function setTimeout to wait for 2 seconds and close the window after that, my script looks like,
    : :
    : : #-----------------------------------------------------------------
    : : #!/usr/bin/perl
    : : print "content-type:text/html

    ";
    : : print qq(
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : );
    : : system "./test.pl &";
    : : #--------------------------------------------------
    : :
    : : and it turns out that the window remains open until the test.pl script finish running, in other word, it's not running in background at all.
    : :
    : : Can anybody help me out here? Any advice would be very appreciated, thanks in advance.
    : :
    :
    :

  • JonathanJonathan Posts: 2,914Member
    Hi,

    Trouble with backticks is that in void context they are a waste of resources as you are capturing output and throwing it away. And as they wait to capture output, I think that they will cause the program to wait too?

    My suggestion - before putting the call to system, put this:-

    close STDOUT;

    That will cause the page to the served to the browser (maybe, hopefully, it works for me, it may not work for you, but give it a spin).

    Hope this helps. And hey there Bradley...long time, no see.

    Jonathan


    : Hello again,
    :
    : I've tried it, and it's not working either, thanks anyway.
    : And I'm running this on a Linux-based server but would like windows user
    : to run the script.
    :
    : : Hi there,
    : :
    : : Try using the backticks (ie. `./test.pl &`;) as it's designed to execute and return a value (if any) as tho the script is being run from the server rather than the System call which needs an exit code from the program and doesn't receive one until it's finished.
    : :
    : : Also, might be a stupid thing to ask, are you running this on a Linux-based server or Windows-based?
    : :
    : : Cya
    : : Bradley q:)
    : :
    : : : Hello everyone.
    : : :
    : : : What I want to do is, let the users click on the button and execute the script in background, plus I use the javascript function setTimeout to wait for 2 seconds and close the window after that, my script looks like,
    : : :
    : : : #-----------------------------------------------------------------
    : : : #!/usr/bin/perl
    : : : print "content-type:text/html

    ";
    : : : print qq(
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : : );
    : : : system "./test.pl &";
    : : : #--------------------------------------------------
    : : :
    : : : and it turns out that the window remains open until the test.pl script finish running, in other word, it's not running in background at all.
    : : :
    : : : Can anybody help me out here? Any advice would be very appreciated, thanks in advance.
    : : :
    : :
    : :
    :
    :


    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • busakornbusakorn Posts: 20Member
    Hello,

    It works really well :-D , thank you very much both of you.

    : Hi,
    :
    : Trouble with backticks is that in void context they are a waste of resources as you are capturing output and throwing it away. And as they wait to capture output, I think that they will cause the program to wait too?
    :
    : My suggestion - before putting the call to system, put this:-
    :
    : close STDOUT;
    :
    : That will cause the page to the served to the browser (maybe, hopefully, it works for me, it may not work for you, but give it a spin).
    :
    : Hope this helps. And hey there Bradley...long time, no see.
    :
    : Jonathan
    :
    :
    : : Hello again,
    : :
    : : I've tried it, and it's not working either, thanks anyway.
    : : And I'm running this on a Linux-based server but would like windows user
    : : to run the script.
    : :
    : : : Hi there,
    : : :
    : : : Try using the backticks (ie. `./test.pl &`;) as it's designed to execute and return a value (if any) as tho the script is being run from the server rather than the System call which needs an exit code from the program and doesn't receive one until it's finished.
    : : :
    : : : Also, might be a stupid thing to ask, are you running this on a Linux-based server or Windows-based?
    : : :
    : : : Cya
    : : : Bradley q:)
    : : :
    : : : : Hello everyone.
    : : : :
    : : : : What I want to do is, let the users click on the button and execute the script in background, plus I use the javascript function setTimeout to wait for 2 seconds and close the window after that, my script looks like,
    : : : :
    : : : : #-----------------------------------------------------------------
    : : : : #!/usr/bin/perl
    : : : : print "content-type:text/html

    ";
    : : : : print qq(
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : );
    : : : : system "./test.pl &";
    : : : : #--------------------------------------------------
    : : : :
    : : : : and it turns out that the window remains open until the test.pl script finish running, in other word, it's not running in background at all.
    : : : :
    : : : : Can anybody help me out here? Any advice would be very appreciated, thanks in advance.
    : : : :
    : : :
    : : :
    : :
    : :
    :
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

Sign In or Register to comment.