Page 1 of 1

Start JScript

Posted: 24 Nov 2014 15:53
by Tonton Luc
Hi,

My JScript :

Code: Select all

curl -k -o result.txt https://www.google.fr
When I put it in a bat file (or js file or cmd file) and start it manually => works fine.
But when I start it programmatically using platformSupport5x::system or shell_native::shellExecute or useExe => doesn't works.
:?:

Posted: 25 Nov 2014 11:46
by Thomas Linder Puls
It is always a good idea to describe what happens; "doesn't work" does not give much info. Are there for example any error messages, or exception dumps?

It is of course also a good idea to show how you have attempted to solve the problem (how did you use useExe and shellExecute).

Anyway, I guess that useExe will need the full path to the curl program, and shellExecute may also need that and it will most likely also need an appropriate verb ("run" I think).

Posted: 25 Nov 2014 13:28
by Tonton Luc
Hi,

When I start manually (double-clic) a bat file with :
all works fine - I recover the contain of this page in result.txt file.

Using this VP7 following code, any result file is created, any error message, a Dos window opened and closed rapidly (I haven't the time to read it) :

Code: Select all

constants     fic_result = "result.txt". clauses     onFileNew(_Source, _MenuTag):-           Fic_js = "recup_url.bat",         Fic_url = "url.txt", % this file contain only https://www.toernooiklapper.nl/tools/index.php         if file::existFile(fic_result) then             try                 file::delete(fic_result) % to clean the result of the preceeding test             catch _ do                 succeed()             end try         end if,         if file::existFile(Fic_js) then             try                 file::delete(Fic_js)             catch _ do                 succeed()             end try         end if,                 if file::existFile(Fic_url) then             try                 file5x::file_str(Fic_url,URL),                 Syntax = string::format("curl -k -o % %",fic_result,URL),                 file5x::file_str(Fic_js,Syntax), % the bat file is created here, and if (after my application is closed) I double-clic manually on it, the command works fine                 if file::existFile(Fic_js) then                     platformSupport5x::system(Fic_js,1,_),                     stdio::write("ok"),stdio::nl % this line works fine but the batch command (started by platformSupport5x::system) doesn't recover the contain of the html page                 end if             catch _ do                 succeed()             end try         else             vpiCommonDialogs::note("Traitement impossible :",string::format("Il manque le fichier suivant :\n\n%",Fic_url))         end if,         !.     onFileNew(_Source, _MenuTag).

Posted: 25 Nov 2014 16:17
by Thomas Linder Puls
platform5x should never be used for new code, it is only there for migration purposes. Please focus on the other methods.

Posted: 26 Nov 2014 11:21
by Tonton Luc
Hi,

Tks for your help.

This following code works fine but only if I add "curl.exe" file in the same folder of my application :

Code: Select all

constants     fic_result = "result.txt". clauses     onFileNew(_Source, _MenuTag):-         Fic_url = "url.txt",         if file::existFile(Fic_url) then             try                 file5x::file_str(Fic_url,URL),                 Syntax_cmd = string::format("start curl -k -o % %",fic_result,URL),                 Exe = useExe::new(string::concat("cmd /c ",Syntax_cmd)),                 Exe:setShowWindow(false),                 Exe:run(),                 stdio::write("ok"),stdio::nl             catch _ do                 succeed()             end try         else             vpiCommonDialogs::note("Traitement impossible :",string::format("Il manque le fichier suivant :\n\n%",Fic_url))         end if.

Posted: 26 Nov 2014 12:02
by Thomas Linder Puls
5x stuff is only for migration not for new code (in 7.3 the socket+... is an exception to this).

Have you tried:

Code: Select all

        Exe = useExe::new(string::format(@"c:\somewhere\curl.exe -k-o % %", fic_result, URL)),
Or perhaps:

Code: Select all

        Exe = useExe::new(string::format(@"-k-o % %", fic_result, URL)),         Exe:setApplicationName(@"c:\somewhere\curl.exe"),
The important part in both cases is to write a path to the exe.

Posted: 26 Nov 2014 14:38
by Tonton Luc
Hi,

Your code doesn't works (maybee for security reasons), but it's nothing because I've a solution with added "curl.exe" file in the same folder of my application.

Many tks to you.
:wink:

Posted: 26 Nov 2014 15:58
by Thomas Linder Puls
I undstand that you are satisfied with the solution you have found.

But the much simpler solution works fine for me. The attached project is made with vip 7.3.

To make it difficult I even use the 64bit version of CURL from the 7.3 program (which is obviously itself 32 bit).

Code: Select all

clauses     run():-         console::init(),         CURL = useExe::new(@"C:\Program Files\cURL\bin\curl.exe -k -o result.txt http://www.visual-prolog.com"),         CURL:run(),         _ = CURL:wait().