Jump to content

How do you use ' and " to combine commands?


rusking

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.