RomanV
(RomanV)
August 13, 2017, 11:56am
1
I am trying to run a .bat file (SendXML) which takes one argument
If I do it from cmd prompt I just type
F:\PathToTheFolder\SendXml E.\cierrez.xml
So I thought I would try with this code, in Xojo
sh.Execute(chr(34)+"F:\\PathToTheFolder\\Sendxml.bat"+chr(34), "E:\\cierrez.xml")
But it did not work, complaining that the system can’t find the XML file
To check which argument was passed to the .bat file I inserted echo %1 in the bat file… and here’s the shell.result (obviosly SendXML did NOT send the XML )
https://drive.google.com/open?id=0B3LQKr6mspNPRGczY0hGU3pWLTg
What is the character before the file path ? Is that the problem ?
Without looking at the bat code, difficult to know what is going on. But shell does not work quite as does the command prompt.
At first glance, though, your code seems ill formed. Those extra quotes and the comma are not necessary IMHO. I would simply do :
dim sh as new shell
sh.execute("F:\\PathToTheFolder\\SendXml.bat E:\\cierrez.xml")
Of course, PathToTheFolder must be the valid path to your SendXml.bat file, and cierrez.xml must be at the root of e:.
What if you just do this?
sh.Execute(chr(34)+"F:\\PathToTheFolder\\Sendxml.bat"+chr(34) + " E:\\cierrez.xml")
BTW, you can double-up quotes to insert them into a string, so this might be easier in the future:
sh.Execute("""F:\\PathToTheFolder\\Sendxml.bat"" E:\\cierrez.xml")
RomanV
(RomanV)
August 13, 2017, 12:07pm
4
here’s the bat code
[code]@echo off
cls
if “%1” == “” goto salgo
echo %1
curl --noproxy 127.0.1.1 http://127.0.1.19/fiscal.xml -H “Content-Type: text/xml” -ss -m 3 --data-binary @%1 > resp.xml
type resp.xml
goto final
:salgo
echo .
echo . ERROR de invocaci¢n… !! - Falta indicar archivo XML.
echo .
echo . Ejemplo: sendxml archivo.xml
echo .
echo .
:final
echo . ### FIN ###
echo .[/code]
RomanV
(RomanV)
August 13, 2017, 12:10pm
5
Hey Kem… I get the same results trying with your suggestion…
I still get that funny character (like a pike or spade) before the path…
RomanV
(RomanV)
August 13, 2017, 12:19pm
6
Michel… is it not E:\cierrez.xml a parameter ?
Shell.Execute(Command as String [,Parameters as String])
Basically, Shell takes the very same syntax as the command prompt. You do not need to separate the parameters with a comma.
But from what I see in your picture, you get an access denied to CierreZ.xml (note there are uppercase there). That is the error.
You have to know that shell cannot elevate privileges. So what you can do as a logged user to access a file on e: may not be available to your app.
You may try instead to launch the bat with parameters.
Something like
Dim f as folderItem = GetFolderItem("F:\\PathToTheFolder\\Sendxml.bat", FolderItem.PethTypeShell)
f.launch("E:\\CierreZ.xml")
RomanV
(RomanV)
August 13, 2017, 12:57pm
8
Michel, thanks for your help… I can’t understand why, but still it is not working…
It’s still complaining that system CANT FIND THE FILE… Isn’t the ? character preceeding the path revealing something ? Is it supposed to be there ?
RomanV
(RomanV)
August 13, 2017, 1:37pm
9
Alright… So I finaaallly… got to the issue…
The problem was within the .bat file… it points to two files… curl(.exe) and resp.xml, which is where the output of curl was supposed to be placed…
As i run the bat from command line I was in the folder containing curl, and the resp.xml but when I run the .bat file from a Xojo shell the inital path was Xojo/whatever/debug/myapp/whatever… therefore the errors… If i set the absolute path of curl and resp.xml in the BAT file… it seems to work ok now.
Thanks for helping out.
RomanV
(RomanV)
August 13, 2017, 1:46pm
10
By the way… How can I start a shell in a certain directory other than the running app folder ?
Already asked by myself and already answered by Michael
https://forum.xojo.com/31960-shell-openup-path
time to have some rest…
Tim_Hare
(Tim Hare)
August 13, 2017, 8:46pm
11
You can’t. That’s basic shell programming 101. Always specify full path names or use system path variables. Never assume anything about where the shell runs. This is true of any batch file programming. It’s not specific to Xojo.