Posts: 4,225
Threads: 365
Joined: May 2005
I am trying to run a batch file from a triggered event and when I test it I get the following error
Could not start external process: c:\CQCDataFiles\testlog.bat
%1 is not a valid Win32 application.
This is the action
System::ExecApp
P1=c:\\CQCDataFiles\\testlog.bat
P2="Test Run of script"
P3=
P4=Show
So I don't understand what is going wrong. It runs fine when executed from the command line.
I tried to search for this issue but did not find anything so I have to ask unfortunately.
Mick
Mykel Koblenz
Illawarra Smart Home
Posts: 40,483
Threads: 491
Joined: Aug 2002
When you run a batch file from the command line, what actually happens is that the command line interpreter runs another program and passes that batch file to it as a parameter, so you have to do the same.
So you would do either:
C:\Windows\system32\cmd.exe /k whatever.bat
or
C:\Windows\system32\cmd.exe /c whatever.bat
/k means keep the window open after it's done, and /c means close the window after it's done. If running from the background then use /c always.
Dean Roddey
Explorans limites defectum
Posts: 4,225
Threads: 365
Joined: May 2005
Is that documented anywhere (and I missed it)?
Does that mean then that P2 will be the parameter to the cmd.exe file being run and what about passing in parameters to the batch file.
i.e. which of the following is correct.
System::ExecApp
P1=C:\\Windows\\system32\\cmd.exe /c c:\\CQCDataFiles\\testlog.bat
P2="Test Run of script"
P3=
P4=Show
System::ExecApp
P1=C:\\Windows\\system32\\cmd.exe
P2=/c c:\\CQCDataFiles\\testlog.bat "Test Run of script"
P3=
P4=Show
or neither.
The batch file has parameters are pssed to it that are used for doing different tasks
Mykel Koblenz
Illawarra Smart Home
Posts: 40,483
Threads: 491
Joined: Aug 2002
The second one would be correct.
Dean Roddey
Explorans limites defectum
Posts: 4,225
Threads: 365
Joined: May 2005
02-11-2015, 03:47 AM
(This post was last modified: 02-11-2015, 03:52 AM by znelbok.)
It does not work.
Well it partially works. The batch file executes but in the batch file is a line to echo to a file and this file is not created.
If I run the same command from the command line the file is created with the passed in parameter as expected. When I run it from a scheduled event CQC return a successful result and the echo is sent to the screen.
cmd /? return quite a number of pages to read, but considering that it works at the command line tells me that I have the syntax right and that CQC might be doing something funky.
Edit
I removed the last parameter that was supposed to be passed into the batch file and the execution was as expected with the file created, but obviously without the value that needs to be passed in causing issues the execution is pointless
Mykel Koblenz
Illawarra Smart Home
Posts: 40,483
Threads: 491
Joined: Aug 2002
Are you running the app shell service as a regular admin account? If not, you might not have the rights to create the file, depending on where you are running it.
Oh, and you might actually need to include the batch file parameters in the same invocation parameter as the batch file itself, so it all gets run as one thing, i.e:
"c:\\CQCDataFiles\\testlog.bat 'Test Run of script'"
Not sure if that will work, but try it. Using the single quotes on the parameter allows the batch file name and the parameter to be quoted.
If that doesn't work, just for sanity's sake, do something like:
"c:\\CQCDataFiles\\testlog.bat TestRunOfScript"
I.e. no spaces so it doesn't need the internal quotes, and see how that does. But I'm guessing that the command line interpreter just passes the whole thing to Cmd.exe as a single parameter and let's it parse it out.
Dean Roddey
Explorans limites defectum
Posts: 4,225
Threads: 365
Joined: May 2005
service runs as my account so it has the right security priv's to write.
The quotes dont work. It tries to run a file named testlog.bat TestRunOfScript i.e. a file by the name of whatever is inside the double quotes.
Mykel Koblenz
Illawarra Smart Home
Posts: 40,483
Threads: 491
Joined: Aug 2002
You'll probably have to do some spelunking to see how what you are sending in is coming out. Go to the Admin Interface and do a simple key mapped action. Have it use /c instead /k so that it leaves the window open. Take out any ECHO OFF from the command line so you can see what is happening.
It may be that the file doesn't get created because the actual value to the command file has the quotes on it, and would need to be stripped off. You'll be able to tell if you do it like above and just ECHO of the parameters sent in and see what they show up as.
Dean Roddey
Explorans limites defectum
Posts: 4,225
Threads: 365
Joined: May 2005
last test yielded a result closer to the desired outcome, but still issues
/c is being used, that is how I was able to report on what I was seeing.
I ran with a parameter "c:\cqcdata\testlog.bat" testrun and the parameter testrun was passed to the batchfile
Tried "c:\cqcdata\testlog.bat" "test run" and no parameter was passed.
Something about the quotes is obviously the key to getting the last parameter to be passed in correctly.
Mykel Koblenz
Illawarra Smart Home
Posts: 40,483
Threads: 491
Joined: Aug 2002
I don't see why there would be any difference between the two from CQC's point of view. Ultimately, when it's invoked testrun will become "testrun" anyway. However, it may be that "test run" becomes ""test run"". That would ultimately turn out to be maybe an empty parm, test, run, and an empty parm. Print out %1, %2, %3, and %4 and see if that is what is happening.
Dean Roddey
Explorans limites defectum