rusking Posted September 23, 2011 Share Posted September 23, 2011 I have 3 variables that im still cleaning up but they produce results at least. I have spent a couple days searching how to execute (exec or shell_exec) them in order. The best iv found, this is done like $statementa = 'cd test"' then do this"' exec=($statementa) but what i am doing is a bit more complicated $tempFolder = 'C:\\xampp\\htdocs\\remote\\'; $filename7Z = 'C:\\xampp\\7-zip\\7z.exe'; $sessionKey = '12345' $commandtest1= 'C:\\xampp\\7-zip\\7z.exe a ' .$tempFolder. 'c' .$sessionKey. '.7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe'; //semi working, copies entire dir $commandtest2 = 'copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+'.$tempFolder.'c'.$sessionKey.'.7z c'.$sessionKey.'.exe'; //create executable in build directory \\\\not working\\\\\\ $commandtest3 = 'del /F /Q '.$tempFolder.'\\c'.$sessionKey.'.7z'; //remove *.7z from %tmp% directory \\\\\\\\\working\\\\\\\ //session_write_close(); exec($commandtest1); Where i cant seem to find any guidance is, if i wrap these in " then is looks fine in dreamweaver but produces nothing. I think it may be the variables but i cant be sure. I tried todo $exec($commandtest1 & $commandtest2) but that didn't help any then i tired ($commandtest1 | $commandtest2) still noting. It seems i can just have three exec so i have to comine into one however i have several breaks where it need todo the first then sencond then third. Please someone point me in the correct direction. I must have read http://php.net/manual/en/function.exec.php at least 6 times and either miss is each time or haven't been able to apply it to my code correctly Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/ Share on other sites More sharing options...
MasterACE14 Posted September 23, 2011 Share Posted September 23, 2011 When wrapping it around double quotes you need to make sure you escape quotes within the string correctly. http://php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271886 Share on other sites More sharing options...
rusking Posted September 23, 2011 Author Share Posted September 23, 2011 hmm im not sure i follow it very well. Let me try.. So would $commandtest and $commandtest2 combined look like $commandtest= "'C:\\xampp\\7-zip\\7z.exe a ' .$tempFolder. 'c' .$sessionKey. '.7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe' copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+'.$tempFolder.'c'.$sessionKey.'.7z c'.$sessionKey.'.exe'"; all the escapes are \\ to indicate that they are backslashes. Or are you saying to drop the ' and replace with " becuase of the below statement? As in single quoted strings, escaping any other character will result in the backslash being printed too. Before PHP 5.1.1, the backslash in \{$var} had not been printed. That makes me think if im using single, that two backslashes will be printed. Wow im even lost in the help lol Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271889 Share on other sites More sharing options...
MasterACE14 Posted September 23, 2011 Share Posted September 23, 2011 hmm im not sure i follow it very well. Let me try.. So would $commandtest and $commandtest2 combined look like $commandtest= "'C:\\xampp\\7-zip\\7z.exe a ' .$tempFolder. 'c' .$sessionKey. '.7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe' copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+'.$tempFolder.'c'.$sessionKey.'.7z c'.$sessionKey.'.exe'"; It should be: $commandtest= "'C:\\xampp\\7-zip\\7z.exe a " .$tempFolder. "c" .$sessionKey. ".7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe' copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+".$tempFolder."c".$sessionKey.".7z c".$sessionKey.".exe'"; If you use double quotes( " ) to start/end the string, when throwing in variables into the string you would need to also use double quotes for that like... $var = "Hello " . $person . ", Enjoy your stay!"; // this works or when using double quotes you could simply do this... $var = "Hello $person, Enjoy your stay!"; // this works It's a little different with single quotes( ' )... $var = 'Hello ' . $person . ', Enjoy your stay!'; // this works this won't parse the variable... $var = 'Hello $person, Enjoy your stay!'; // will display $person instead of it's value Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271890 Share on other sites More sharing options...
rusking Posted September 23, 2011 Author Share Posted September 23, 2011 so in winvnc.exe' copy /b is the php sending return (enter) after the winvnc.exe and then sending copy /b etc...? Because i cant really see whats happening and i don't see a result. I think i may have tried this but scratched it because it produced nothing. I assume if this is in fact correct there is a minor problem with the execution. I cant be sure without seeing it. One time i tried the exec($comamndtest , $output) , reading this from the tutorial or help i never say were $output was defined. i think i used a >2 something another aswell and still not much luck. I keep trying to find a logging process till after i did the code looked soo messy i was confused what i was doing again. I guess what im asking is what is the cleanest most efficient way to log the out put so i see where the failure is in the suggestion you gave me. Not saying your wrong, i just may have not stated something earlier. Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271894 Share on other sites More sharing options...
gizmola Posted September 23, 2011 Share Posted September 23, 2011 Take a look at shell_exec. Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271899 Share on other sites More sharing options...
rusking Posted September 23, 2011 Author Share Posted September 23, 2011 Please someone point me in the correct direction. I must have read http://php.net/manual/en/function.exec.php at least 6 times and either miss is each time or haven't been able to apply it to my code correctly I have and am still not sure how, as in my last statement i get mixed or useless results. Not sure which $results or >2 etc to use Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271907 Share on other sites More sharing options...
rusking Posted September 23, 2011 Author Share Posted September 23, 2011 Opps my bad, you pointed to a diff site...will read Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271908 Share on other sites More sharing options...
rusking Posted September 23, 2011 Author Share Posted September 23, 2011 <?php $tempFolder = 'C:\\xampp\\htdocs\\remote\\'; // location of temporary folder (must be writable by webserver), DON'T include trailing slash $filename7Z = 'C:\\xampp\\7-zip\\7z.exe'; // 7zip executable filename '7za' or '7zr' $sessionKey = 'iworked'; $commandtest = "'C:\\xampp\\7-zip\\7z.exe a " .$tempFolder. "c" .$sessionKey. ".7z C:\\xampp\\htdocs\\remote\\client\\' copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+".$tempFolder."c".$sessionKey.".7z c".$sessionKey.".exe'"; $output = exec($commandtest); echo "<pre>$output</pre>"; ?> No file and a blank page. Don't see any output results. Any ideas...i must be missing something very basic Quote Link to comment https://forums.phpfreaks.com/topic/247680-how-do-you-use-and-to-combine-commands/#findComment-1271917 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.