2

Before I remembered how to accomplish what I was doing, I tried a couple different things, kind of just hacking at it.
What I was trying to accomplish was to set the following string as a variable and then echo it out in a batch script:

<?php require('__php__.php'); ?>

I eventually worked it out with help from SO, but before I got there, I tried this (for some reason):

 set (phpStr=<? php require('__php__.php'); ?>)

Which I realize doesn't make any sense. However, how the cmd shell interpreted what I wanted to do was as follows:

 set (phpStr= php require('__php__.php'); ? 0<? 1>)

In other words, when I typed the code in the second code block above, and turned on echo in the script, what showed up in the cmd shell was the command in the third code block. Then there was a syntax error, and the script exited.

Can anyone explain what happened? (Not why it didn't work. That is obvious to me, but rather, how it arrived at the interpretation it did. It's a pretty awesome restructuring of the original command. I just can't figure out how it got there.)

dgo
  • 3,877
  • 5
  • 34
  • 47
  • AIUI Stackoverflow is for answers to programming questions - if you want to discuss the way CMD functions in all sorts of ways then you might be better off posting to a forum like http://www.dostips.com/forum/ where some very cluey people discuss batch related phenomena - as well as help people with more mundane tasks. It mentions XP in the forum title but all versions of Windows are discussed. – foxidrive Aug 25 '13 at 15:48

1 Answers1

0

You need to escape redirection and other poison characters with ^ or the redirection will be active and try to create files etc. % is a special case.

You can also use something like this:

@echo off
for /f "delims=" %%a in ("<?php require('__php__.php'); ?>") do echo %%a
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • That's useful. I didn't think about using the /f switch. However, it doesn't answer my question. – dgo Aug 25 '13 at 03:53
  • The redirection is active and trying to create files - it is invalid batch syntax. What more do you need to know? – foxidrive Aug 25 '13 at 03:58
  • Look at the difference between the second and third code block. It rearranges character order. There is something happening that is responding to the parenthesis and triangle bracket. I want to understand this because it seems like it could have useful applications if I understood it. – dgo Aug 25 '13 at 17:03