-1

It turns out my FTP client smushed my shell script, so thanks to everyone who contributed. :)

===============================

I'm trying to use PHP to execute a shell script stored in the same directory as my PHP script using exec(), but I get an error:

sh: 1: ./hlsvod.sh: not found

I've tried using the full path to the script, I've chmodded it 777, I've tried using shell_exec() but I still get the same error (I redirected the stderr to stdout to get it). The script definitely exists. Could you help?

Code:

<?php
/* Probably not the most elegant solution but it works. */
$pid = $_GET['pid'];
if(empty($_GET['pid'])){
    die("No PID -- do ?pid=XXXXXXXX");
}
$tmpfile = exec("./hlsvod.sh ".$pid." 2>&1");

echo nl2br(shell_exec("pwd;whoami;"));
var_dump($tmpfile);
$a = fopen($tmpfile."m3u8", "r");
$stream = fread($a);
fclose($a);
$b = fopen($tmpfile."subs");
$subs = fread($b);
fclose($b);
var_dump($stream);
var_dump($subs);
?><!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width,user-scalable=no">
<title>New 3DS iPlayer - <?=$pid;?></title>
</head>
<body>
<h1>Live HLS Stream for <?=$pid;?></h1>
<p>HLS stream URL: <a href="<?=$stream;?>"><?=$stream;?></a></p>
<p>VTT subtitles URL: <a href="<?=$subs;?>"><?=$subs;?></a></p>
<video id="video" controls preload="metadata">
   <source src="<?php echo $stream; ?>">
   <track label="English" kind="subtitles" srclang="en" src="<?=$subs;?>" default>
</video>
</body>
</html>
Eva Lauren Kelly
  • 403
  • 1
  • 4
  • 15

3 Answers3

1

Try using the absolute path like this

$tmpfile = exec("sh: 1: " . $_SERVER["DOCUMENT_ROOT"] . "/hlsvod.sh ".$pid." 2>&1");
Julio Soares
  • 1,200
  • 8
  • 11
0

Turned out my FTP client smushed up the line endings and messed all sorts up in my shell script.

Watch your line endings!

Eva Lauren Kelly
  • 403
  • 1
  • 4
  • 15
-1

check this link for executing shell commands using php

<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
source and for more check this

http://php.net/manual/en/function.shell-exec.php

Ananta Prasad
  • 3,655
  • 3
  • 23
  • 35