R
R
Roman2012-01-26 10:43:23
PHP
Roman, 2012-01-26 10:43:23

PHP: Running multiple shell commands?

There is a task to take screenshots of web pages, for this I use the CutyCapt console utility, since an x-server is needed for its operation, I launch it through a fake xvfb, for example:

xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=... --out=...

but I need to do several screenshots of different pages at a time, I try this
xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=...

in the console all this works fine, but through php f-th system it processes only the first command, up to && and gives one screen. How would you decide?
PS I think that you can somehow solve it through a bash script (.sh), but unfortunately I'm not strong in this, and I would still like some solution without perversion (it also doesn't work, it only executes the first command)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2012-01-26
@WNeZRoS

<?php
  if(isset($_POST['urls'])) {
    $urls = explode("\n", trim((string)$_POST['urls']));
    $sh = time() % rand(1000,9999) * rand(10,99); $sh .= '.sh';
    
    $f = fopen($sh, 'w');
    foreach($urls as $k=>$v) {
      fwrite($f, '/usr/bin/cutycapt --url='.trim($v).' --out=img'.$k.'.png'."\n");
    }
    fclose($f);
    
    system('/usr/bin/xvfb-run --server-args="-screen 0, 1024x768x24" /bin/bash '.$sh);
    
    foreach($urls as $k=>$v) {
      echo '<img src="img'.$k.'.png">
';
    }
  }
?>
<form action="capt.php" method="POST">
<textarea name="urls"></textarea>
<input type="submit">
</form>

It works for me like this

R
Riateche, 2012-01-26
@Riateche

Try like this:
bash -c 'xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=...'

S
Silentium, 2012-01-26
@silentium

And if so to put quotes?
xvfb-run --server-args="-screen 0, 1024x768x24" './CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=... && ./CutyCapt --url=... --out=...'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question