🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.misc
Article #2043

Re: How to launch a shell script (.sh) from an HTML page ?

#2043
From: Alex Mitrofanov
Date: Tue, 23 Oct 2001 17:41
84 lines
3643 bytes
David Winter wrote:
> 
> Hi,
> 
> I'm sure somebody already posted the solution some time ago, but I couldn't
> find it.
> I need to launch a sheel script (.sh file) from an HTML page under unix
> (Solaris and others).
> I am NOT using any server: this only a LOCAL html page. No virtual
> directories.
> 
> Right now I am using the following code, that is executed from an image
> button in an HTML <form>:
> 
> <script>
> function openMyFile ()
> {
>     if (document.layers)
>     {
>         var exePath = new String('. ./test.sh');

You can't use `.', it is a sell command.

> 
> netscape.security.PrivilegeManager.enablePrivilege('UniversalExecAccess');
>         java.lang.Runtime.getRuntime().exec(exePath);
>     }
> }
> </script>
> 
> The test.sh file changes the current directory in order to run another sh
> that launches a java application.
> 
> I have tried several shell commands, such as:
> 
>     '. ./test.sh'
>     './test.sh'

Are you sure netscape's current directory is where you put your script?

Try this page:

<html>
<head>
<script>
function openMyFile ()
{
    if (document.layers)
    {
     	var exePath = new String('/full/path/to/test.sh');  

netscape.security.PrivilegeManager.enablePrivilege('UniversalExecAccess');
        java.lang.Runtime.getRuntime().exec(exePath);
    }
}
</script>
</head>
<body onload="openMyFile()">
</body>
</html>

and script:

#!/bin/sh
cd /usr/X11R6/bin
./xterm

Don't forget to give execution permission.
If it works modify it for your needs.
> 
> but no luck. Nothing happens and my sh file is not launched.

Look in javascript console, you can open it by typing `javascript:' in
the location field.

> Any ideas ? Please reply in this newsgroup.

Which one? I've set follow-ups to comp.unix.questions.

HTH,
--
Alex Mitrofanov
Brainbench MVP for Unix Programming
http://www.brainbench.com
Technical Details
Message-ID: <3BD5AABC.DF245068@inphinity.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.bc.home.com.POSTED!not-for-mail
References: <9r3fue$6k5$1@news.businessobjects.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8c9b,ce5dc68f68e2e00a
X-Google-Attributes: gidf8c9b,public
X-Google-Thread: fe1d2,ce5dc68f68e2e00a
X-Google-Attributes: gidfe1d2,public
X-Google-Thread: fa664,ce5dc68f68e2e00a
X-Google-Attributes: gidfa664,public
X-Google-Thread: f72b0,ce5dc68f68e2e00a
X-Google-Attributes: gidf72b0,public
X-Google-Thread: 110f2c,ce5dc68f68e2e00a
X-Google-Attributes: gid110f2c,public
X-Google-Thread: 11035d,ce5dc68f68e2e00a
X-Google-Attributes: gid11035d,public
X-Google-Thread: 1012a6,ce5dc68f68e2e00a
X-Google-Attributes: gid1012a6,public
X-Google-ArrivalTime: 2001-10-23 10:41:10 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.bc.home.com.POSTED!not-for-mail
Message-ID: <3BD5AABC.DF245068@inphinity.com>
From: Alex Mitrofanov <alex.mitrofanov@inphinity.com>
Organization: Inphinity Interactive Inc.
X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686)
X-Accept-Language: en, ru
MIME-Version: 1.0
Newsgroups: comp.unix.misc,comp.unix.questions,comp.unix.sco.misc,comp.unix.sco.programmer,comp.unix.shell,comp.unix.solaris,fr.comp.os.unix
Followup-To: comp.unix.questions
Subject: Re: How to launch a shell script (.sh) from an HTML page ?
References: <9r3fue$6k5$1@news.businessobjects.com>
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit
Lines: 84
Date: Tue, 23 Oct 2001 17:41:10 GMT
NNTP-Posting-Host: 24.77.234.11
X-Complaints-To: abuse@home.net
X-Trace: news1.rdc1.bc.home.com 1003858870 24.77.234.11 (Tue, 23 Oct 2001 10:41:10 PDT)
NNTP-Posting-Date: Tue, 23 Oct 2001 10:41:10 PDT