executing a windows batch file .bat from servoy

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

executing a windows batch file .bat from servoy

Postby dpearce » Sat Mar 14, 2009 9:10 pm

Hi,

I am trying to execute a windows batch file from within servoy. I cant see anyone doing this on the forum, nut have got the execute in background statement to not come up with an error, but yet the file doesn't seem to run:

Code: Select all
application.executeProgramInBackground( '"C:\\Program Files\\COREX\\Corex Local\\postupdatetest.bat"')
(single quotes outside double ones).

this line works fine from the run prompt (obviously without the double backslahes.

Has anyone had experience of running .bat files from within servoy?

Thanks

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: executing a windows batch file .bat from servoy

Postby Hans Nieuwenhuis » Sat Mar 14, 2009 10:15 pm

Hi,

did a litle test.

Created a file called d.bat in the directory c:\h1\h2

the file d.bat contains
Code: Select all
cd \temp
dir >c:\l.lst


i created a buuton in a form with the following code
Code: Select all
application.executeProgram('c:\\h1\\h2\\d.bat');



This works fine.

the following also works
Code: Select all
application.executeProgramInBackground('c:\\h1\\h2\\d.bat');



Regards,

Hans
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: executing a windows batch file .bat from servoy

Postby dpearce » Sun Mar 15, 2009 12:53 am

Hans,

many thanks.

I think that does work. My problem and the reason I am doing this (although a bit wacky!) is to create a servoy offline solution that is capable of updating itself!

On the Mac it work fine. I download the new sybase repository file using ftp, copy the .db into the database folder, delete the old log file and immediately close the solution.
On starting again, it creates a new log file and hey presto, I have just cracked the chestnut of providing updates using servoy for a servoy offline solution.

On good old Windows, none of the Java file functions, to delete or move files onto what is a read only sybase file in use, work.

So my aim her was to create a bat file that ran in the background with a 5 second pause that when the application quit would move the files and replace the servoy_repository file once sybase which closes on application shutdown released the lock!

Code: Select all
@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n 10 -w 1000> nul

DEL /F database\servoy_repository.db
DEL /F database\servoy_repository.log

MOVE database\new\servoy_repository.db database\servoy_repository.db


This does the trick from the command line. The problem i think is that as soon as servoy closes it must stop the bat file running as it is the parent of the process. Or thats what i think.

Many moons ago in Perl, I would have switched the standard input from the requesting web browser! (crashed Demons servers in 1995 doing that when writing a robot the could function without my dial up connecting costing me a fortune.)

So I challenge any windows servoy techies out there:

How can i force delete or move a file from java that will overwrite a windows read only file that is in use or

Is there anyway to sporn a .bat process that will continue after Servoy shuts down until complete. The reason I need a few seconds is for Sybase to close and release the servoy_repository files from being in use.

Many thanks for any suggestions

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: executing a windows batch file .bat from servoy

Postby alexander.sternadel » Fri Nov 29, 2024 8:18 am

Does this also work with the web-client?

For some reason this does not work in web-client, when called from the browser:
Code: Select all
application.executeProgram("C:\\TEMP\\hello_world.bat")


but this does work:
Code: Select all
application.executeProgram('rundll32', ['url.dll,FileProtocolHandler', 'C:\\TEMP\\hello_world.bat'])


My issue is that I need to start cmd or powershell with arguements and by calling the rundll32 I cannot pass arguments to cmd / powershell.

Cheers,
Alexander
alexander.sternadel
 
Posts: 14
Joined: Fri Nov 22, 2024 1:33 pm

Re: executing a windows batch file .bat from servoy

Postby mboegem » Fri Nov 29, 2024 10:23 am

Hi Alexander,

what do you mean with web-client?
The most recent versions of Servoy only run Titanium Client (TiNG)
Any of the previous client-flavours (smart-client, web-client, NG-client) are deprecated and should be updated to TiNG to allow for future support.

Anyway, any of the web-based clients run their code serverside.
This means that any action or process that requires Java (like the application.executeProgram) will run server-side.

If you need to have interaction with client-side OS, this is only possible using the (Ti)NG-client and the corresponding service-packages that you can install through the Package Manager.

I assume you are currently testing in developer and here's one big gotcha: in developer your client (browser) and server (java) are running on the same machine.
Therefor, if you're trying to interact with a file on your desktop, this seems to work in developer as the server-part is able to access your desktop.
Once deployed, the code will still work but can only access a file on the desktop of the server, not your client desktop.

I guess the direction you are trying to go now is impossible, but a little hard to judge as there is no further context on what you want to achieve executing this batch file.
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1808
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: executing a windows batch file .bat from servoy

Postby alexander.sternadel » Fri Nov 29, 2024 12:06 pm

Hi Marc,

yes, we are running the Titanium Client.

The batch-file is only on the developer-PC so that we can access it during testing. Once ready it will move to the server so that it can be accessed.
The idea is to start the batch file on the server so that it starts a mkdir or robocopy, so nothing the user will interact with.

The problem is, that calling it like this works in the developer, but this way I cannot give any parameters to the batch file:
Code: Select all
application.executeProgram('rundll32', ['url.dll,FileProtocolHandler', 'C:\\TEMP\\hello_world.bat'])


This version should also work in the developer, but doesn't. The browser only shows a loading icon but cannot start the batch file.
Code: Select all
application.executeProgram("C:\\TEMP\\hello_world.bat")
alexander.sternadel
 
Posts: 14
Joined: Fri Nov 22, 2024 1:33 pm

Re: executing a windows batch file .bat from servoy

Postby mboegem » Fri Nov 29, 2024 5:04 pm

Hi Alexander,

I might be mistaken, but if you just add the parameter as a 3rd argument, doesn't that work?
Code: Select all
application.executeProgram('rundll32', ['url.dll,FileProtocolHandler', 'C:\\TEMP\\hello_world.bat', 'Alexander'])
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1808
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: executing a windows batch file .bat from servoy

Postby alexander.sternadel » Mon Dec 02, 2024 7:43 am

Unfortunately this doesn't work.
alexander.sternadel
 
Posts: 14
Joined: Fri Nov 22, 2024 1:33 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 10 guests