0

I am using linux commands like "rm -f" or executing some exe through php shell_exec but the command is not working in same manner as linux command line. What can be the problem? Thanks in Advance

$myfile = fopen("preOrder.txt", "w") or die("Unable to open file!");
if (isset($_POST['submit'])) { 
    $strg = $_POST['myText']; 
    fwrite($myfile, $strg); 
    fclose($myfile);
    $lyparser_log=shell_exec('./lyparser.out < preOrder.txt');
    $file1=fopen("log.txt","w"); 
    fwrite($file1,$lyparser_log);
}
Lawrence Johnson
  • 3,924
  • 2
  • 17
  • 30
Akhil Bhatia
  • 17
  • 1
  • 3
  • 3
    Could you please post a snippet of your code? – Lawrence Johnson Jan 01 '16 at 05:28
  • @LawrenceJohnson if (isset($_POST['submit'])) { $strg = $_POST['myText']; fwrite($myfile, $strg); fclose($myfile); $lyparser_log=shell_exec('./lyparser.out < preOrder.txt'); $file1=fopen("log.txt","w"); fwrite($file1,$lyparser_log); – Akhil Bhatia Jan 01 '16 at 05:36

2 Answers2

0
  1. you can try the following code

    exec("rm -rf a\\");

Sana
  • 25
  • 7
  • 1
    Consider revising with an explanation as to what results you expect or what you intend to help the OP with reaching a solution to the question. If you are trying to get more information, it would be preferable to use comments on the question. – Lawrence Johnson Jan 01 '16 at 05:57
  • Like we use touch command in cmd to create file or rm to remove but I am not able to do do through php shell_exec The above code you see I am trying to run a executable file but its output in cmd and php shell_exec are different. – Akhil Bhatia Jan 01 '16 at 06:11
0

You can execute this like that in PHP:

$yourCommand = ""; // use your command here like **rm -f**
shell_exec($yourCommand); // or any other command pass in this function.

From PHP Manual:

This function will execute command via shell and return the complete output as a string.

Side Note: If you have all permission and still this function not work, than check your PHP.INI file and remove shell_exec from disable_functions.

devpro
  • 16,184
  • 3
  • 27
  • 38