Question

Locked

PHP System commands

By dr.engnr ·
I'm trying to execute the following system commands throught php:

system("tracert -d 4.2.2.2 | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"http://who-is.net/php-nslookup.php?host=\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> trace.txt");

i'm getting an 'invalid syntax' error. It seems to have to do with the quotes, but they're necessary for the command. Any help is appreciated.

thanks.

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

btw

by dr.engnr In reply to PHP System commands

this is a windows machine with unxutils installed. most unix commands are available.

Collapse -

Question about gawk

by NetMan1958 In reply to PHP System commands

I didn't know you could post to a web url from within gawk. Are you sure that is possible? I thought you would have to use curl for that.

Collapse -

gawk

by dr.engnr In reply to Question about gawk

it's actually just pulling the individual data i need from the tracert and surrounding the $8 column with url text.

Collapse -

Quotes

by NetMan1958 In reply to PHP System commands

Try replacing the double-quotes before tracert and after trace.txt with single quotes. For instance:

system('tracert -d 4.2.2.2 | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"http://who-is.net/php-nslookup.php?host=\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> trace.txt');

I can't test that right now so let me know the results.

edited to add:
see this article
http://me.abelcheung.org/2009/01/19/windows-process-execution-on-php-with-double-quotes/

Collapse -

yeah

by dr.engnr In reply to Quotes

This seems to be "better". instead of immediately failing it is processing but no file is exported. I have tried assigning the command to a variable $command and printing it. It can be pasted directly into a prompt and runs fine.

is there a reason anyone can see that >> wouldn't work as written?

Collapse -

Try This

by NetMan1958 In reply to yeah

system('tracert -d 4.2.2.2 | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"http://who-is.net/php-nslookup.php?host=\"$8\"^&submit=ReverseIP\" \",\" \"Window2\" >> trace.txt}"');

Collapse -

negative

by dr.engnr In reply to Try This

damn. i've tried about every combination of ' and " i can conceive.

Collapse -

strange

by dr.engnr In reply to Try This

the text file actually gets created using the following code, but it stays empty even though the script appears to be running.
<code>
system('tracert -d who-is.net | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"http://who-is.net/php-nslookup.php?host=\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> H:\WHO-IS.NET\trace.txt ');
</code>


any idea what i have to do?

Collapse -

Output Redirection

by NetMan1958 In reply to strange

Since gawk is what is actually creating the output that you want in the file, you need to move your output re-direction(>> H:\WHO-IS.NET\trace.txt) inside the curly braces.

I don't have PHP running on a windows machine so I can't experiment with it here.

Collapse -

finally

by dr.engnr In reply to strange

what a p.i.t.a. just figured out what it was. because i am using unxutils i had to copy the grep.exe and gawk.exe into the c:\windows directory as well as system32. even though the commands function correctly when pasted to a prompt i guess the system() command needs all files in both locations...

fyi

Back to Windows Forum
10 total posts (Page 1 of 1)  

Related Forums