quote and double-quote " " "
quote and double-quote " " "
Hello,
I have the following command that woks OK:
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\gsc.exe" -o "%outtemp1%" -sDEVICE=pdfwrite "%A_LoopFilePath%" pdfmark.txt "
As it can be seen there are TWO quote marks one at the begining (after /c) and the other at the end (after pdfmark.txt)
If i do not add the last quote mark it will NOT work, and this understandable OK.
But here is a strange behavior at the following command:
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
As it can be seen there are TWO quote marks one at the begining (after /c) and the other at the end (after "%out1%")
BUT - here is the QUESTION --> If i do not add the last quote mark it will AGAIN work.
BUT it should NOT work. WHY it works please?
I will appreciate your commentσ
Thank you very very much!
I have the following command that woks OK:
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\gsc.exe" -o "%outtemp1%" -sDEVICE=pdfwrite "%A_LoopFilePath%" pdfmark.txt "
As it can be seen there are TWO quote marks one at the begining (after /c) and the other at the end (after pdfmark.txt)
If i do not add the last quote mark it will NOT work, and this understandable OK.
But here is a strange behavior at the following command:
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
As it can be seen there are TWO quote marks one at the begining (after /c) and the other at the end (after "%out1%")
BUT - here is the QUESTION --> If i do not add the last quote mark it will AGAIN work.
BUT it should NOT work. WHY it works please?
I will appreciate your commentσ
Thank you very very much!
Re: quote and double-quote " " "
Do you by chance have a double-quote in one of the variables? Out1 maybe?
Code: Select all
out1 = has a quote"
Msgbox % out1
Re: quote and double-quote " " "
Yes , this is a very interesting point - actually the only point make sense, but i can not see where is this EXTRA WRONG quote mark.
The 3 variables used are as follows:
BUT, can you please see where is this EXTRA WRONG quote mark ?
The 3 variables used are as follows:
Code: Select all
FileSelectFolder output1,, 3, Select the output directory
SplitPath A_LoopFilePath,,,extens, fnBare
out1 := output1 "\Converted_Files\" fnBare "." extens
outtemp1 := output1 "\Converted_Files\" "Temp" "\" fnBare "." extens
BUT, can you please see where is this EXTRA WRONG quote mark ?
Re: quote and double-quote " " "
The only significant difference I see between your first example (that works), and the second example (that doesn't work) is that the string ends with text in the first, and ends with a variable in the second. This might affect how it is out together prior to performing the Run.
Try this:
Try this:
Code: Select all
cmdStr = "%A_ScriptDir%\DATA\qpdf.exe --empty --pages %outtemp1% -- %out1%"
Runwait, cmd.exe /c %cmdStr%
Re: quote and double-quote " " "
Thank you for that point.
But please note regarding my first question:
Note that the above it is working OK.
The question is:
If i do not add the last quote mark it will AGAIN work.
BUT it should NOT work. WHY it works please?
Where is the "tric" ?
But please note regarding my first question:
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
The question is:
If i do not add the last quote mark it will AGAIN work.
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
Where is the "tric" ?
Re: quote and double-quote " " "
It's hard to say, because I am unable to run this exact command to test different theories. So all I can do is to offer tests so you can see if anything changes. This may provide clues to the cause.
Try removing the spaces from the end quotes? Does this run?
Runwait, cmd.exe /c ""%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%""
Your original question is a good one. I don't see the cause. Sometimes these things pop up and don't make sense to most of us. In those times we need the insight from the developer @lexikos. There is usually an answer and sometimes he is the only one who can provide it.
There are also others here that are very sharp and may eventually provide an answer that eludes limited intellect such as mine.
Last edited by andymbody on 05 Oct 2023, 17:14, edited 1 time in total.
Re: quote and double-quote " " "
You should always endeavour to use correct syntax, even if it appears to work otherwise, as a later update may tighten the syntax checking and cause an error message. In this case I expect either 'cmd.exe' or 'qpdf.exe' tolerate the mistake and make a silent correction.
Cheers
Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Re: quote and double-quote " " "
Hello,
Please let me explain my findings through TWO examples:
Example 1:
Example 2:
As it is clearly seen from the above TWO examples the commands are working in BOTH CASES, that is:
CASE A --> Initial quote mark (after cmd.exe /c) WITHOUT closing quote at the very end (after pdfmark.txt)
CASE B --> Initial quote mark (after cmd.exe /c) AND closing quote at the very end (after pdfmark.txt)
Note:
The above are valid and working for BOTH EXAMPLES (1 - gsc.exe) and (2 - qpdf.exe)
(Excuse me because in my initial post comment i say something different - that was mistake)
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE A or CASE B)?
Please let me explain my findings through TWO examples:
Example 1:
Code: Select all
SetWorkingDir, %A_ScriptDir%
out1 := A_ScriptDir "\output.pdf"
outtemp1 := A_ScriptDir "\input.pdf"
;BOTH the following commands are working
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
Example 2:
Code: Select all
SetWorkingDir, %A_ScriptDir%
out1 := A_ScriptDir "\output.pdf"
outtemp1 := A_ScriptDir "\input.pdf"
;BOTH the following commands are working
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\gsc.exe" -o "%out1%" -sDEVICE=pdfwrite "%outtemp1%" "%A_ScriptDir%\DATA\pdfmark.txt"
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\gsc.exe" -o "%out1%" -sDEVICE=pdfwrite "%outtemp1%" "%A_ScriptDir%\DATA\pdfmark.txt" "
As it is clearly seen from the above TWO examples the commands are working in BOTH CASES, that is:
CASE A --> Initial quote mark (after cmd.exe /c) WITHOUT closing quote at the very end (after pdfmark.txt)
CASE B --> Initial quote mark (after cmd.exe /c) AND closing quote at the very end (after pdfmark.txt)
Note:
The above are valid and working for BOTH EXAMPLES (1 - gsc.exe) and (2 - qpdf.exe)
(Excuse me because in my initial post comment i say something different - that was mistake)
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE A or CASE B)?
Re: quote and double-quote " " "
I would say this is because the entire command is enclosed in quotes either way. I may be wrong, but I think the inner quotes are considered text, not quotes, no matter how many there are (from the perspective Runwait). And I don't think the inner quotes are needed for Runwait to perform its job. The outer quotes are needed tho, since there are spaces in the full command.
Which is why I asked you earlier to try the example below that only has outer quotes, but no inner quotes. Does this one work?
Try this:
Code: Select all
cmdStr = "%A_ScriptDir%\DATA\qpdf.exe --empty --pages %outtemp1% -- %out1%"
Runwait, cmd.exe /c %cmdStr%
Re: quote and double-quote " " "
Hello,
CASE I
Yes, i try it and also your suggestion is working:
CASE II
Also according to your thoughts, the following is working:
CASE III
Also as mention in my earlier comment the following is working:
CASE IV
And also as mention in my earlier comment the following is working:
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE I or CASE II OR CASE III or CASE IV)?
CASE I
Yes, i try it and also your suggestion is working:
Code: Select all
cmdStr = "%A_ScriptDir%\DATA\qpdf.exe --empty --pages %outtemp1% -- %out1%"
Runwait, cmd.exe /c %cmdStr%
CASE II
Also according to your thoughts, the following is working:
Code: Select all
Runwait, cmd.exe /c " %A_ScriptDir%\DATA\qpdf.exe --empty --pages %outtemp1% -- %out1% "
CASE III
Also as mention in my earlier comment the following is working:
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
CASE IV
And also as mention in my earlier comment the following is working:
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE I or CASE II OR CASE III or CASE IV)?
Re: quote and double-quote " " "
In this case I would suggest 1 or 2, but not 3 or 4 since they are confusing and include unnecessary quotes.
I suspect that the only time you need the inner quotes is if a path has spaces, but yours did not in this case.
For instance if the path was
%A_ScriptDir%\DATA 123\gsc.exe you would surround in quotes like this:
"%A_ScriptDir%\DATA 123\gsc.exe"
These inner quotes are for cmd.exe, not Runwait.
But I could be wrong about that. Someone else with more knowledge may be able to provide more correct info.
Andy
Re: quote and double-quote " " "
Hello,
I try it and i confirm that your suspect is valid, that is if a path has spaces it NEEDS the inner quotes.
So to GENERALIZE the whole matter:
CASE I
CASE II
CASE III
CASE IV
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE I or CASE II OR CASE III or CASE IV)?
(I personally prefer CASE IV), but what is your opinion, please?
I try it and i confirm that your suspect is valid, that is if a path has spaces it NEEDS the inner quotes.
So to GENERALIZE the whole matter:
CASE I
Code: Select all
cmdStr = " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages %outtemp1% -- %out1% "
Runwait, cmd.exe /c %cmdStr%
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages %outtemp1% -- %out1% "
CASE III
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
CASE IV
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
FINALLY, according to the above, the FINAL QUESTION is the following:
STRICTLY speaking, what is the "more" correct SYNTAX to use? (CASE I or CASE II OR CASE III or CASE IV)?
(I personally prefer CASE IV), but what is your opinion, please?
Re: quote and double-quote " " "
If I were writing it, I would be doing it in v2 which allows single and double quotes and would do it similar to case 1. In v1 I would probably choose case 1 as well. Because I prefer to put strings in variables so I can inspect them when it doesn't work correctly (debugging). And I can name a variable in a descriptive way that tells me what it is for.
Re: quote and double-quote " " "
Thank you very much all for your help on this topic.
You really help me.
Please let me further discuss:
(1)
If i want to use CASE IV, is it OK to use, i mean is it correct programmatically, please?
(2)
Only one last think i did not understand it is regarding CASE iii :
Why it is working since the very end quote mark is missing?
"Programmatically" it shouldn't work.
Any explanation, please?
(3)
Also instead of using
I have the opinion from what i read until now, that it is better in order to ENSURE working in any cases to use:
In other words %comspec% is BETTER than cmd.exe. Do you agree with me, please?
I will appreciate your comments in (1), (2), and (3) , please.
You really help me.
Please let me further discuss:
(1)
If i want to use CASE IV, is it OK to use, i mean is it correct programmatically, please?
(2)
Only one last think i did not understand it is regarding CASE iii :
Code: Select all
Runwait, cmd.exe /c " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
"Programmatically" it shouldn't work.
Any explanation, please?
(3)
Also instead of using
Code: Select all
Runwait, cmd.exe
I have the opinion from what i read until now, that it is better in order to ENSURE working in any cases to use:
Code: Select all
Runwait, %comspec%
I will appreciate your comments in (1), (2), and (3) , please.
Re: quote and double-quote " " "
I rarely use Run. So I am learning from your post. But if it works the way you prefer, continue to use it until it doesn't.
As I stated earlier, I think the inner quotes are ignored by Run. The inner quotes would be used by cmd.exe. As you have demonstrated, it seems that cmd.exe may be very forgiving as @TAC109 suggested. But I cannot confirm this without testing.(2)
"Programmatically" it shouldn't work.
Any explanation, please?
As you were told in your separate post/thread on this question, Comspec may be the preferred method. I cannot confirm this because I have very little knowledge or experience with it. But the explanation made sense to me since the system uses this variable to point to the actual file path for cmd.exe. It's there for convenience and the environment variables were used a lot before Windows (in DOS days), and are still being used apparently. So it has not been abandoned, and points to a pretty safe bet to use it with confidence.(3)
Is %comspec% BETTER than cmd.exe.
Re: quote and double-quote " " "
I am really THANK YOU very very much for all your help!
My final conclusion is the following:
I will finally use CASE IV with %comspec%, as follows:
WHY:
Because using CASE IV, covers ALL cases including the scenario where ANY path has spaces.
And also i will use %comspec% instead of cmd.exe because it is a better choice, since "covers" all the cases to ALWAYS do the "job" (even in the scenario where there is a change of the Path variable).
Please, if you see any reason that you believe i have a mistake regarding my above final conclusion, i will be very happy to comment here in order to correct my final conclusion.
Thanks!
My final conclusion is the following:
I will finally use CASE IV with %comspec%, as follows:
Code: Select all
Runwait, %comspec% /c " "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%" "
Because using CASE IV, covers ALL cases including the scenario where ANY path has spaces.
And also i will use %comspec% instead of cmd.exe because it is a better choice, since "covers" all the cases to ALWAYS do the "job" (even in the scenario where there is a change of the Path variable).
Please, if you see any reason that you believe i have a mistake regarding my above final conclusion, i will be very happy to comment here in order to correct my final conclusion.
Thanks!
Re: quote and double-quote " " "
It is not clear from your code that it is necessary to run your program using either cmd.exe or %comspec% in the first instance. Have you tried this? In this case you would instead need to code the RunWait command like this:
Cheers
Code: Select all
Runwait, "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Re: quote and double-quote " " "
Unfortunately it is not working without using cmd.exe or %comspec%.TAC109 wrote: ↑06 Oct 2023, 17:37It is not clear from your code that it is necessary to run your program using either cmd.exe or %comspec% in the first instance. Have you tried this? In this case you would instead need to code the RunWait command like this:CheersCode: Select all
Runwait, "%A_ScriptDir%\DATA 123\qpdf.exe" --empty --pages "%outtemp1%" -- "%out1%"
So, according to your comment
Do you agree with my final conclusion that "covers" ALL situations, and it is good choice to use - that is CASE IV with %comspec% ?
Who is online
Users browsing this forum: Bing [Bot], Spawnova and 270 guests