in reply to Run the process in the background

If you want to start something into the background and not wait for it to finish before returning to Perl, use fork() (which actually threads under Windows)

Alternatively you can use the Windows command start to start something in the background. You can use system( "start mycommand.exe" ); from Perl

I hope that's the question you're asking... ;) I think the error message you're seeing is from your application rather than Perl. You can put system( "command" ) and die "$!\n"; to see if the application returns anything over STDERR as well to check.

Update:The poster had previously not mentioned the OS being used - the use of cmd fooled me into thinking it was Windows :)

Replies are listed 'Best First'.
Re^2: Run the process in the background
by perl@newbie (Novice) on Aug 31, 2005 at 14:39 UTC
    Hej Monks, I think i have caused too much confusion. I will rephrase the question.
    First of all the environment: Linux(tcsh shell) and perl version 5.8.3. Problem: I want to do something like this
    system("long command to be executed on the tcsh in the background &").
    If i run this long command from the prompt it doesnt give me any error. But If i run it using system and exec inside perl script (with or without fork), command is executed succesfully, prompt is returned but i get an error message on the prompt. Scenarios that i have tried to perform as suggested by you all
    =>using system function - system("command &") && die(" From Sys func: $!"); Executes my command and Returns the prompt but it gives an error after returning the prompt "write to host (-1) failed in SendMessageToHost" Note that i dont get illegal seek this time and the error mesg is not coming from die
    => using fork as suggested by cowboy with exec for executing the command on the shell exec(" command &") && die("From Exec function: $!"); Prompt returns, gets the similar error "write to host (-1) failed in SendMessageToHost"
    => using sys command inside fork or otherwise but having die as an OR condition system("command &") || die("From sys function: $!"); This time i get "From sys function: Illegal seek" error and then the prompt returns and gives the error "write to host (-1) failed in SendMessageToHost"
    Most of you have pointed out that the error may be coming from the command. Command works fine for me when i run it on the prompt. And i get these errors only from within perl script. Thanx