iceman Posted June 9, 2011 Posted June 9, 2011 I am trying to use CR with parameters to limit dates. If I make the paramdef xml file using the \PARAMDEF switch, alter the dates in it and use a batch file to run CR with the \PARAMFILE parameter pointing at the file it works OK. However, (trying to avoid using the file) if instead I take the contents of the xml file and simply pass that entire string as a \PARAMS parameter CR gives me this error. '1.0' is an unexpected token. The expected token is '"' or ''' Line 1, Position 15. That corresponds to the first part of the xml where it states the version i.e /PARAMS:" Has anyone used \PARAMS sucessfully? BTW I would prefer to do it with a \PARAMS instead of PARAMSFILE as in my real application I use a Delphi program to call CR, not a batch file. However that seems to fail if I use either the /PARAMFILE or /PARAM swich, but works OK if I dont use parameters at all. Howard
vikpaw Posted June 9, 2011 Posted June 9, 2011 Can you just omit the XML declaration tag, and pass in only the report parameters tags onwards. Remove the xml closing tag too.
LosOjos Posted June 9, 2011 Posted June 9, 2011 The problem is that on the command line, when it reaches a quotation (") it thinks that's the end of your literal input. So you need to escape any quotations that must be included by doubling them up, for instance the above example would become: /PARAMS:" Personally, I find it easier to construct my XML in code and dump it to an XML file and pass that as an argument
iceman Posted June 9, 2011 Author Posted June 9, 2011 Hi vikpaw, I tried it with just /PARAMS:" Mark date Date MarkDateBefore 2011-06-09T00:01:00 Mark date Date MarkDateAfter 2010-08-15T23:59:00 " and this time got an unrecognised token on DDNzGLsaAUi8eGtd+3PIGw== Howard
vikpaw Posted June 9, 2011 Posted June 9, 2011 My bad @iceman - i was just guessing. @LosOjos has the answer i reckon with needing to escape the quote marks. Sometimes using double instead of single can do the trick. I think passing the file would make more sense otherwise you're going to have to hack around with the quotes. I feel another script coming on...
iceman Posted June 9, 2011 Author Posted June 9, 2011 Vikpaw, You were right you can just use the bits from the to the - at least on the command line you can . I also doubled up the quotes just in case but it didn't seem to matter if I did or not it still ran OK. Thanks for getting it shorter. The odd thing is that I still cannot get it to run from a Delphi program using CreateProcess() . This function should run an external program and pass it parameters. It works fine when I use it to run CR with the user, pw and output parameters but fails if I pass the Params one as well, even though I copy paste the string that works fine on the command line. Something is very odd. Howard
LosOjos Posted June 9, 2011 Posted June 9, 2011 The odd thing is that I still cannot get it to run from a Delphi program using CreateProcess() . This function should run an external program and pass it parameters. It works fine when I use it to run CR with the user, pw and output parameters but fails if I pass the Params one as well, even though I copy paste the string that works fine on the command line. Something is very odd. You seriously do need to escape your characters, I'm shocked it runs on the command line without doing so, but you'll have to look up how to escape characters in Delphi (a quick Google suggests it's doubling up the character as I said previously)
iceman Posted June 9, 2011 Author Posted June 9, 2011 They are all escaped. As a debug I write out the parameters being passed to CreateProcess just before it runs. The relevant one is /PARAMS:" Mark date Date MarkDateBefore 2011-06-09T00:01:00 Mark date Date MarkDateAfter 2010-08-15T23:59:00 " the whole thing is enclosed in single quotes as required by CR. I also wrote a dummy commandreporter.exe that simply wrote out the parameters it was being sent. Interestingly it claimed to get /PARAMS: Mark date Date MarkDateBefore 2011-6-13T00:01:00 Mark date Date MarkDateAfter 2010-8-15T23:59:00 so its possible that either CreateProcess or the mechanism by which a program extracts its parameters is stripping out even escaped double quotes.
LosOjos Posted June 9, 2011 Posted June 9, 2011 Seems odd... what is the reason that you can't just dump it in to an XML and pass the XML file as the argument? That's what I always do as I gave up battling with getting it to run from the command line a long time ago
nickbro Posted June 9, 2011 Posted June 9, 2011 They are all escaped. As a debug I write out the parameters being passed to CreateProcess just before it runs. The relevant one is the whole thing is enclosed in single quotes as required by CR. I also wrote a dummy commandreporter.exe that simply wrote out the parameters it was being sent. Interestingly it claimed to get so its possible that either CreateProcess or the mechanism by which a program extracts its parameters is stripping out even escaped double quotes. Try /PARAMS:"Mark dateDate MarkDateBefore2011-06-09T00:01:00Mark dateDateMarkDateAfter2010-08-15T23:59:00" It's all down the the quote marks, dos only sees the double quotes, so if you use "" it will just see end of one quote start of another, which it doesn't like. Using ' instead gets around this.
LosOjos Posted June 9, 2011 Posted June 9, 2011 Try /PARAMS:"Mark dateDate MarkDateBefore2011-06-09T00:01:00Mark dateDateMarkDateAfter2010-08-15T23:59:00" It's all down the the quote marks, dos only sees the double quotes, so if you use "" it will just see end of one quote start of another, which it doesn't like. Using ' instead gets around this. I'm interested to see if that works, as that would actually make the XML volatile which should mean it's rejected...
iceman Posted June 9, 2011 Author Posted June 9, 2011 OK I've tried runing it via the dos prompt with single quotes and even no quotes! both work OK However when I pass the same command line to CreateProcess it fails to run CR claiming a file handle error. Passing the same command line to createprocess but ommiting the Params parameter works OK. Putting the xml in a file also works OK from the dos prompt but once again fails when CR is called via createProcess and the filename is passed (Thats why I was trying this alternative approach) Howard
nickbro Posted June 10, 2011 Posted June 10, 2011 I'm interested to see if that works, as that would actually make the XML volatile which should mean it's rejected... It does work, as I use it in several SIMS report apps that I've made to update stuff on our computer system. XML will work with single or double quote, most people use double, but single is perfectly fine. 1
vikpaw Posted June 11, 2011 Posted June 11, 2011 OK I've tried runing it via the dos prompt with single quotes and even no quotes! both work OK However when I pass the same command line to CreateProcess it fails to run CR claiming a file handle error. Passing the same command line to createprocess but ommiting the Params parameter works OK. Putting the xml in a file also works OK from the dos prompt but once again fails when CR is called via createProcess and the filename is passed (Thats why I was trying this alternative approach) Howard I thought there was a way to pass parameters direct, so at least that worked. Now thinking in psuedo code: It seems delphi or the createprocess() function wants the parameters a certain way. How does it function for say running a 'dir' command...? Does wrapping the whole lot in quotes make any difference? Can you get Delphi to just call the batch file, so directly or using createprocess() on the CR.bat that does work...? If escaping the quotes doesn't work how about interchanging the double and single, if possible within the limitation mentioned above about only one type being recognised. I think i recall, in one particularly complicated html / php code i wrote, i had 3 levels of embedded quotes, and rather than escape them, it was necessary for the master level to be single, then sub params double and then the embedded ones to be single again. It's damned hard to read (and troubleshoot) but does do the trick. Maybe if you can replicated the issues with commandreporter with another simpler program with less complex parameter requirements you can test a few things out.
iceman Posted June 11, 2011 Author Posted June 11, 2011 (edited) Sorted it. It was not Createprocess at all. the folder in which I was running my app and into which I was writing the xml file was hidden with read/write acces only to me. It appears that when CR gets run by CreateProcess it runs using different credientials. Moving everything to a different folder worked OK. However I'll leave a challenge to the community. As Vikpaw says, It would be better to use the /PARAMS: switch instead and place the xml directly after it (as one big quoted string) to avoid having to write an xml file at all. Problem is the xml contains spaces and quotes. Createprocess parses the line and does some quote stripping and so does the command line interpretor before it passess the arguments to commandreporter. Challenge Find the correct sequence of escapes to generate a command string that can be passed to CreateProcess() to run a report via commandreporter with the following argument ! /PARAMS:" Mark date Date MarkDateBefore 2011-06-10T00:01:00 Mark date Date MarkDateAfter 2010-08-15T23:59:00 " Edited June 11, 2011 by iceman spelling!
vikpaw Posted June 11, 2011 Posted June 11, 2011 @iceman - that's torture to a room full of geeks! I don't even have delphi, and it would be needed to do any form of testing, can you at least give me the full syntax that your using, so i can see the quote mark usage on the whole string... i'll run it through my quote stripper/parser and see what it comes back with.
Arthur Posted June 11, 2011 Posted June 11, 2011 if you use "" it will just see end of one quote start of another, which it doesn't like. Using ' instead gets around this. Escaping the second set of each pair of double quotes with a \ seems to work for me. /PARAMS: Mark date Date MarkDateBefore 2011-06-09T00:01:00 Mark date Date MarkDateAfter 2010-08-15T23:59:00 http://i.imgur.com/9qDN9.png ArgsTest.exe can be downloaded from here.
iceman Posted June 11, 2011 Author Posted June 11, 2011 Arthur, Every second pair! I must admit that was one combination I didn't try. I'll try that out with the real thing and post back. Vicpaw The full line I would like to pass to CreateProcess to avoid making a file is below. It refers to a report based on student with a sub report of attendance marks and (following your comments from a much earlier post) with two parameters for the start date and end date with prompt names of MarkDateAfter and MarkDateBefore. I generate these dates using code, change them to a string and, at the moment, embed them into the short bit of xml that gets written to a file. What I have below is preferable though if I can get the format right. Oh, and the actual file paths will be full UNC paths containing double backslashes and Dollar signs, this example is from my development machine. "C:\Program Files\sims\sims .net\commandreporter.exe" /USER:"d" /PASSWORD:"x" /REPORT:"SITKA_Attendance" /OUTPUT:"K:\Howards Documents\SITKA\jobs\Attendance\Delphi version\delphi code version 2\init\SITKA_Attendance.csv" /PARAMS:" Mark date Date MarkDateBefore 2011-06-10T00:01:00 Mark date Date MarkDateAfter 2010-08-15T23:59:00 "
localzuk Posted June 11, 2011 Posted June 11, 2011 Can I ask why you are avoiding creating a temp file to do the job? It'd save a heck of a lot of faffing with very little drawback that I can see?
iceman Posted June 11, 2011 Author Posted June 11, 2011 Localzuk I've had no end of hassle with different microsoft office versions / invalid registry values / unregistered components / changed or incorrect folder and user permissions preventing me from doing what I want to do with my programs. Consequently I have re-coded (am in the process of re-coding) all my analysis systems from a mixture of Access and Excel with some VBA thrown in to stand alone, fully compiled programs written in Delphi. As you can see from my earlier post, once again folder permission reared their head when I wrote out the xml file to the same folder from which I was running my program and yet command reporter was unable to then read from that folder due to permissions and the credentials under which CR appeared to be running. Therefore I am trying to limit as much as possible any reading and writing of files that is not absolutely necessary. If I can get away with one single SIMS export (OK a few exports) and then do everything else via my program then I know I'm in complete control and not at the mercy of network changes and software upgrades performed by sombody else.
iceman Posted June 11, 2011 Author Posted June 11, 2011 (edited) Arthur, I couldn't get it to work. The whole /PARAMS: value must also be in double quotes as it contains spaces and CreateProcess delimits by spaces. I tried /PARAMS:""Mark date Date MarkDateBefore2011-06-11T00:01:00Mark date Date MarkDateAfter2010-08-15T23:59:00\""' And got the following passed into commandreporter (actually a dummy version of CR that simply prints out its parameters) Paramcount = 15 parameters passed are: 0: C:\Program Files\sims\sims .net\commandreporter.exe 1: /USER:d 2: /PASSWORD:x 3: /REPORT:SITKA_Attendance 4: /OUTPUT:K:\Howards Documents\SITKA\jobs\Attendance\Delphi version\delphi code version 2\init\SITKA_Attendance.csv 5: /PARAMS:6: id=\DDNzGLsaAUi8eGtd+3PIGw== 7: subreportfilter=\True>Mark 8: date 9: Date 10: MarkDateBefore2011-06-11T00:01:0011: id=\eNvt6kqoTcUAoHB2VMyWRg== 12: subreportfilter=\True>Mark 13: date 14: Date 15: MarkDateAfter2010-08-15T23:59:00\ Did you get your result passing the string to CreateProcess() which then called argstest with the parameter or did you call argstest directly. Obviously there is quite a difference as there is only one layer of parsing with the latter whereas with createprocess() the line gets mangled before argstest even gets to see it. Edited June 11, 2011 by iceman added a bit
Arthur Posted June 12, 2011 Posted June 12, 2011 After a lot of trial-and-error, this is the best I can come up with (the PARAMS bit has double double quotes). argstest "\"C:\Program Files\SIMS\Sims .net\CommandReporter.exe"\" /USER:"\"d"\" /PASSWORD:"\"x"\" /REPORT:"\"SITKA_Attendance"\" /OUTPUT:"\"K:\SITKA_Attendance.csv"\" /PARAMS:\"""\""Mark dateDateMarkDateBefore2011-06-09T00:01:00Mark dateDate MarkDateAfter2010-08-15T23:59:00"\"""" http://i.imgur.com/J7RPc.png
iceman Posted June 12, 2011 Author Posted June 12, 2011 Thanks for your efforts Arthur but it still gets mangled when being pre-processed by CreateProcess(), which appears to do escape character conversions all of its own before even CR sees it and still splits on spaces and refuses to send out any quote chars. Ah well, you have pointed me in the right direction. Another project to put on my laptop for the summer holidays!
vikpaw Posted June 12, 2011 Posted June 12, 2011 Instead of escaping doesn't it work by interchanging single and double quotes depending on what level you are at? So start with double around the lot then the next set use single then after that double again.. either that second double works or closes the first lot and starts the second lot in which case you can start with single again. Not sure that made sense :s What about putting the string into a string variable and then passing that in as a parameter is that doable..? either the whole string or just the params part..
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now