Wednesday 15 July 2015

shell - Perl -- command executing inside a script hangs -


When I run the following script, it does exactly what I have to do and get out:

SetDisplay.sh:

  #! / Bin / bash Xvfb -fp / usr / share / fonts / X11 / misc /: 22-screen 0 1024x768x16 2 & gt; And 1 & amp; Export DISPLAY =: 22   

When I run ./ setDisplay.sh , everything works fine.

OK, this is where the fun begins ...

I have a Perl script which sets the call ...

Here is the eamorr.pl script:

  #! Use / usr / bin / perl strict; Use warnings; My $ homeDir = "/ home / eamorr / dropbox / site /"; My $ CMD; My $ result; Print "----- Setting up the display ... \ n"; $ Cmd = "sh $ homedir / set display."; Print $ CMD "\ N"; $ Result = `$ cmd`; Print result;   

When I run ./ eamorr.pl

then I'm completely trapped < / Div>

When you do this:

  $ result = '$ cmd`;   

The pellel process is created by adding an external command, and Pearl reads from that pipe to EOF.

Your external command creates a background process that still has pipes on your stdout (and since its stderr you did 2 & gt; & amp; 1 ) There will be no eof on that pipe unless it exits from the background process or its standout and stadder closure or redirects elsewhere.

If you want to collect stdout and stderr of Xvfb Perl variable $ result , you have to wait to end it naturally If you do not want to do this, then I think that you have to do 2 & gt; & Amp; 1 .

Also the script which is export command is questionable. It can only modify its own environment, and then it immediately comes out so there is no effect, generally it is an indication that someone can modify the process of parenting Is trying, which is not possible.

No comments:

Post a Comment