Freedom-n-Democrazy Posted September 23, 2011 Author Share Posted September 23, 2011 like\\ this? If so, still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271921 Share on other sites More sharing options...
trq Posted September 23, 2011 Share Posted September 23, 2011 The actual command will need a single \, this means you will need two because you are using a double quoted string. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271922 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 23, 2011 Author Share Posted September 23, 2011 The code now sits at: <?php $link = mysql_connect('localhost', 'testusr', 'testpw'); mysql_select_db('testdb', $link); $query = "select fordir from products where id=".$_POST['id'].""; $result = mysql_query($query); $fordir = mysql_fetch_array($result); $query = "select category from products where id=".$_POST['id'].""; $result = mysql_query($query); $category = mysql_fetch_array($result); $query = "DELETE from `products` where `id` = ".$_POST['id'].""; $cmd = "cp -rf /var/www/http/test.com/products/{$fordir['fordir']}/{$category['category']}/{$_POST['id']} /home/n/Documents/test.com\\ codebase"; echo "command is: $cmd <BR>"; $retval = shell_exec($cmd); echo $retval; echo "result: $retval"; mysql_query ($query); mysql_close($link); ?> The code echo's fine: command is: cp -rf /var/www/http/test.com/products/men/belts/69 /home/n/Documents/test.com\ codebase result: ... and works when I paste it into my Linux shell, but its not working in PHP. Not even a mention of it in error.log. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271924 Share on other sites More sharing options...
gizmola Posted September 23, 2011 Share Posted September 23, 2011 Things that don't produce an error don't go into the error log. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271925 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 23, 2011 Author Share Posted September 23, 2011 Which is what disturbs me the most, as there is clearly an error... or even a paradox! Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271926 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 23, 2011 Author Share Posted September 23, 2011 I am now using: system ("mkdir /1"); system ("mkdir /home/n/1"); system ("mkdir /var/www/http/test.com/1"); FAIL FAIL SUCCESS I smell write permission problems. But fuckin PHP didn't say this in error.log!!!!!!!! I will continue to test and let you guys know.... I think I am a noob. I forget PHP will running as www-data and not root!!!! OMG Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271931 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 23, 2011 Author Share Posted September 23, 2011 Yep, it was a write permission issue. There must be a bug in PHP where it doesn't log system() errors. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1271933 Share on other sites More sharing options...
gizmola Posted September 23, 2011 Share Posted September 23, 2011 Which is what disturbs me the most, as there is clearly an error... or even a paradox! Well it depends on how you look at it. To php the function call is the shell_exec. It is completing. If the cp command executes but doesn't execute in the way you want, to php it is still executing. There are also a number of php.ini settings that can stop operating system commands from running, as well as operating system permissions, and environment issues that can effect a script running. I don't think that is the source of your problem but you should read about them and check against your configuration just to be sure: http://us3.php.net/manual/en/ini.sect.safe-mode.php The way php is being used is another issue. How these external calls work or not is highly dependent on the operating system, the webserver and the way it's been configured. There's just way too much involved for me to summarize. Since these commands seem to work for you from the shell an quick way around your problem might be to make a bash script that takes parameters, unit test that and call the bash script in your shell_exec. You can in your script redirect std output and stderr to a file. In fact you might experiment with that just with the current command you are running. I did note that you are using spaces in directory names -- not a great idea, since they add more things that could go wrong as Thorpe pointed out. For example, one of your paths -- I can't remember which one, has a space in it. Quote Link to comment https://forums.phpfreaks.com/topic/247642-how-to-use-the-system-argument-correctly/page/2/#findComment-1272130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.