Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#1 Post by mm@muellermario.de » 16 Feb 2016 07:37

HI all,

i wrote a BAT, which reads a customizing/properties CSV-File.
When I start the BAT via clicking in the windows explorer or via Windows-Button > R (un) enerything is fine.

Now I want to start the BAT via HTML.
The BAT echos an ERROR <Could not find "Customizing.csv">

Could anybody please explain, why this error occurs and how to avoid this?

Thanks
Regards
Mario

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#2 Post by foxidrive » 16 Feb 2016 10:13

mm@muellermario.de wrote:Now I want to start the BAT via HTML.

I can't fathom how you are using HTML to launch a batch script.

For instance, a Web browser can't launch a batch script using plain HTML.

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#3 Post by kwsiebert » 16 Feb 2016 15:14

I believe an HTML document can execute a batch script through CGI.

If that is the case, what's probably happening is that the working directory is the one the HTML server is running from, and not the one the batch file is in. Have your batch file either use the full path to the CSV file, or preferably, explicitly change the current directory to where the script is located.

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#4 Post by mm@muellermario.de » 16 Feb 2016 23:54

Hi all,

@foxidrive: Yes, ist is possible to start.

example:

Code: Select all

<head>
</head>
<body>
<input type="button" value="Name of the batch file" onclick="window.open('file:///G:/../.../THIS_IS_A_BAT_FILE.bat')"/>
</body>


@kwsiebert

Good answer! Can I anyhow invstigate on which working directory this script is running after calling via HTML?


And yes: I used the absolute - and not the relative - path.
REgards
Mario

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#5 Post by foxidrive » 17 Feb 2016 00:46

mm@muellermario.de wrote:
@foxidrive: Yes, ist is possible to start.

example:

Code: Select all

<head>
</head>
<body>
<input type="button" value="Name of the batch file" onclick="window.open('file:///G:/../.../THIS_IS_A_BAT_FILE.bat')"/>
</body>



All good, except it doesn't work in a standard web browser.


Code: Select all

echo @echo here^&pause>c:\test\FILE.bat

(
echo ^<head^>
echo ^</head^>
echo ^<body^>
echo ^<input type="button" value="Name of the batch file" onclick="window.open('file:///c:/test/FILE.bat')"/^>
echo ^</body^>
) > file.html
start file.html

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#6 Post by ShadowThief » 17 Feb 2016 02:06

mm@muellermario.de wrote:Can I investigate which working directory this script is running after calling via HTML?


Code: Select all

echo %cd%

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#7 Post by kwsiebert » 17 Feb 2016 09:41

foxidrive wrote:All good, except it doesn't work in a standard web browser.

Agreed. I tried it in the most current Firefox with no success. The file path isn't correctly escaped, for starters, but even when I fixed that, all it does is display the contents of the batch file in the browser window. Nothing is actually executed.

julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#8 Post by julesverne » 17 Feb 2016 12:39

kwsiebert wrote:
foxidrive wrote:All good, except it doesn't work in a standard web browser.

Agreed. I tried it in the most current Firefox with no success. The file path isn't correctly escaped, for starters, but even when I fixed that, all it does is display the contents of the batch file in the browser window. Nothing is actually executed.


@kwsiebert if your goal is to run it locally on windows machines you should look into creating an hta. You won't be able to view it in firefox or chrome. What it does is use something installed on windows as mshta.

More information can be found here:
https://msdn.microsoft.com/en-us/librar ... 96(v=vs.85).aspx

Microsoft used to have a program called the hta helpomatic but it was taken down. It's kinda handy for those who don't know vbscript. It helps you builds hta files. I have it on my computer and the screenshot below is what it looks like.

http://img.brothersoft.com/screenshots/ ... 92692.jpeg

But I know jscript works with hta and javascript will too.

mm@muellermario.de
Posts: 12
Joined: 20 Feb 2015 08:24

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#9 Post by mm@muellermario.de » 17 Feb 2016 21:22

@julesverne:

Your link is unfortunately not working.


https://msdn.microsoft.com/en-us/librar ... 96(v=vs.85).aspx

I would appreciate if you correct ist.

Regards
Mario

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Call BAT-File (which uses as properties.csv ) from JAVASCript/HTML

#10 Post by ShadowThief » 18 Feb 2016 01:36

Just add the string ).aspx to the URL that you go to when you click the link...

And if you're too lazy to do that, try this:
https://msdn.microsoft.com/en-us/library/ms536496(v=vs.85).aspx

Post Reply