Aretai Posted March 1, 2007 Share Posted March 1, 2007 Hi, I'm using Solaris 10. I want to create a simple on-line search form for the files stored on my OS (it's trusted environment). The problem for me is redirecting to a different directory. My php file is stored in: "/usr/local/php" and I would like to search for the content of the files stored in the "/home/test/" The script itself is working for the "ls" command (I get files stored in /home/test), however when I run it for diff command it displays info relevant for "/usr/local/php". What should be changed? ??? <?php $filepath = "home/test"; $len = strlen($filepath); $command="pwd"; //$command="ls -l \"{$filepath}\""; //$command="ls -l \"{$filepath}\""; $command = "grep -i test * \"{$filepath}\""; $output = shell_exec($command); echo "<pre>$output</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/ Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 however when I run it for diff command it displays info relevant for "/usr/local/php" Im not sure I understand? Do you mean your running the diff command or another different command. Can you post the code that is NOT working? Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196934 Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 <?php $filepath = "home/test"; $len = strlen($filepath); $command="pwd"; //$command="ls -l \"{$filepath}\""; //$command="ls -l \"{$filepath}\""; $command = "grep -i 'test' /home/me/my_docs/* \"{$filepath}\""; $output = shell_exec($command); echo "<pre>$output</pre>"; ?> Try putting the path in front of the files you want to search (like I did above) Also note the quotes around 'test'. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196939 Share on other sites More sharing options...
mrheff Posted March 1, 2007 Share Posted March 1, 2007 try ../../home/path going back up first? xcuse me if this sint an option im still fairly new to this. Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196949 Share on other sites More sharing options...
Aretai Posted March 1, 2007 Author Share Posted March 1, 2007 <?php $filepath = "home/test"; $len = strlen($filepath); $command="pwd"; //$command="ls -l \"{$filepath}\""; //$command="ls -l \"{$filepath}\""; $command = "grep -i 'test' /home/me/my_docs/* \"{$filepath}\""; $output = shell_exec($command); echo "<pre>$output</pre>"; ?> Try putting the path in front of the files you want to search (like I did above) Also note the quotes around 'test'. monk.e.boy Tried this - even without assigning directory to a variable (i.e. dir is fixed) $command = "grep -i 'test' /home/test/*"; but it's not working. However this command is working under OS. Wonder what can cause an error - I only get a blank page (and I know there should be some result). Tried to debug with: <?php ini_set("display_errors","1"); ?> but nothing is returned Aretai Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196958 Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 Post your actual code. Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196962 Share on other sites More sharing options...
Aretai Posted March 1, 2007 Author Share Posted March 1, 2007 My actual code is: <?php ini_set("display_errors","1"); ?> <?php $filepath = "home/test"; $len = strlen($filepath); $command = "grep -i 'test' /home/test/*"; $output = shell_exec($command); echo "<pre>$output</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196966 Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 I think you need to save the results somewhere: grep -i 'hello' /my/path/* > /my/web/site/results.txt Then after this has run, pull the file into your page with file_get_contents( 'results.txt' ) Note all the different paths. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196970 Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 This works fine for me. <?php $out = shell_exec("grep -i 'test' /home/thorpe/test/*"); echo "<pre>$out</pre>"; ?> Are you sure /home/test is correct? Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-196991 Share on other sites More sharing options...
Aretai Posted March 1, 2007 Author Share Posted March 1, 2007 Ok it's working know - some minor bug I haven't noticed Link to comment https://forums.phpfreaks.com/topic/40697-grep-php/#findComment-197372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.