Question
Nordea
SE
Last activity: 22 May 2016 2:56 EDT
How to launch/open Notepad from a button
Hi All,
Any idea how to launch or open Notepad from a pega screen button.
I tried with JAVA code but Runtime.exec("") is getting error.
Please help.
Thanks,
Kousik
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 16 May 2016 10:17 EDT
Pegasystems Inc.
GB
I tried this Java Step in an Activity (it's a mangled-version of the Code-Pega-PDF.VIEW activity) on a PRPC6210 system (which I happened to have running - it should still work on later versions of PRPC).
ClipboardPage objHeadersPage = tools.findPage("pxRequestor").getProperty(".pyHTTPResponseHeaders").getPageValue(); objHeadersPage.putString("contentType" ,"text/plain"); objHeadersPage.putString("ContentDisposition" ,"attachment;filename=test.txt"); String contents="Hello World"; byte[] bContents=contents.getBytes(java.nio.charset.Charset.forName("UTF-8")); String result=tools.sendFile(bContents,"test.txt", false, null, true);
This works when I launch it from Designer Studio - I haven't tried it in other PRPC contexts (I don't forsee any problems there though).
This launches Notepad on my system; but it is actually leaving the decision to the Browser/Client Operating system to find a 'matching' program for 'txt' files.
The 'Content-Disposition' header hints to the browser that this should be treated as an attachment, rather than (the default for 'text/plain') launching 'in-browser'.
On my system ; the browser behaviour is to ask the end-user what they want to do with the file:
I tried this Java Step in an Activity (it's a mangled-version of the Code-Pega-PDF.VIEW activity) on a PRPC6210 system (which I happened to have running - it should still work on later versions of PRPC).
ClipboardPage objHeadersPage = tools.findPage("pxRequestor").getProperty(".pyHTTPResponseHeaders").getPageValue(); objHeadersPage.putString("contentType" ,"text/plain"); objHeadersPage.putString("ContentDisposition" ,"attachment;filename=test.txt"); String contents="Hello World"; byte[] bContents=contents.getBytes(java.nio.charset.Charset.forName("UTF-8")); String result=tools.sendFile(bContents,"test.txt", false, null, true);
This works when I launch it from Designer Studio - I haven't tried it in other PRPC contexts (I don't forsee any problems there though).
This launches Notepad on my system; but it is actually leaving the decision to the Browser/Client Operating system to find a 'matching' program for 'txt' files.
The 'Content-Disposition' header hints to the browser that this should be treated as an attachment, rather than (the default for 'text/plain') launching 'in-browser'.
On my system ; the browser behaviour is to ask the end-user what they want to do with the file:
This is a 'one-way' process; the resultant text editor (notepad in my case, and in most default cases I guess) is not in any way able to save the data back to the PRPC.
Cheers
John
GovCIO
US
Hi Kousik,
Try using the below Java Script from any of Pega HTML rules and see if this works for you or not. Not sure whether your client allows to use this ActiveX concept from the browser stand point.Usually clients won't accept to make browser side settings on ActiveX but it is up to you.
<Script>
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = <%= tools.findPage("workPropPage").getProperty("pyWorkPage.AppPath").toString() %>;
oShell.ShellExecute(commandtoRun,"","","open","1");
</Script>
Thanks,
Ravi Kumar.
Nordea
SE
Hi Ravi,
Thanks for your reply. It didn't even work for my general HTML. Could you please provide me code to launch notepad in simple HTML.
I think I am getting confused somewhere in ActiveX configuration or the passing relative path of the exe file.
Please reply.
Thanks,
Kousik
Nordea
SE
Hi Ravi,
Below code worked for me:
<script type = "text/Javascript">
function go() {
w = new ActiveXObject("WScript.Shell");
w.run('notepad.exe');
return true;
}
</script>
<form>
Run Notepad (Windows with Internet Explorer only)
<input type="button" value="Go" onClick="return go()">
</form>
Thanks,
Kousik
Updated: 16 May 2016 9:46 EDT
Pegasystems Inc.
GB
Hi Kousik,
I don't think you can rely on browser's allowing this kind of thing going forward: it's regarded (quite correctly I think) as a security risk for a browser to run arbitary, unsigned-code / local executables on the client desktop.
At the very least - It won't work outside of Internet Explorer either of course (ActiveX-based).
My system blocked the HTML when I tried it on IE11 on Windows7 (I'm glad it did: since 'notepad.exe' could be something worse!)
Cheers
John
Nordea
SE
Hi John,
Thanks for your reply. I am aware of your concern and understand it.
Can please provide some other way to launch/open notepad from a button?
Regards,
Kousik
Pegasystems Inc.
GB
Do you to plan to have the user type something into notepad and then save it back to the server as well ? or literally just open a client-side program for them ?
Nordea
SE
Looking forward to both the scenarios. What can be the solutions for both?
Accepted Solution
Updated: 16 May 2016 10:17 EDT
Pegasystems Inc.
GB
I tried this Java Step in an Activity (it's a mangled-version of the Code-Pega-PDF.VIEW activity) on a PRPC6210 system (which I happened to have running - it should still work on later versions of PRPC).
ClipboardPage objHeadersPage = tools.findPage("pxRequestor").getProperty(".pyHTTPResponseHeaders").getPageValue(); objHeadersPage.putString("contentType" ,"text/plain"); objHeadersPage.putString("ContentDisposition" ,"attachment;filename=test.txt"); String contents="Hello World"; byte[] bContents=contents.getBytes(java.nio.charset.Charset.forName("UTF-8")); String result=tools.sendFile(bContents,"test.txt", false, null, true);
This works when I launch it from Designer Studio - I haven't tried it in other PRPC contexts (I don't forsee any problems there though).
This launches Notepad on my system; but it is actually leaving the decision to the Browser/Client Operating system to find a 'matching' program for 'txt' files.
The 'Content-Disposition' header hints to the browser that this should be treated as an attachment, rather than (the default for 'text/plain') launching 'in-browser'.
On my system ; the browser behaviour is to ask the end-user what they want to do with the file:
I tried this Java Step in an Activity (it's a mangled-version of the Code-Pega-PDF.VIEW activity) on a PRPC6210 system (which I happened to have running - it should still work on later versions of PRPC).
ClipboardPage objHeadersPage = tools.findPage("pxRequestor").getProperty(".pyHTTPResponseHeaders").getPageValue(); objHeadersPage.putString("contentType" ,"text/plain"); objHeadersPage.putString("ContentDisposition" ,"attachment;filename=test.txt"); String contents="Hello World"; byte[] bContents=contents.getBytes(java.nio.charset.Charset.forName("UTF-8")); String result=tools.sendFile(bContents,"test.txt", false, null, true);
This works when I launch it from Designer Studio - I haven't tried it in other PRPC contexts (I don't forsee any problems there though).
This launches Notepad on my system; but it is actually leaving the decision to the Browser/Client Operating system to find a 'matching' program for 'txt' files.
The 'Content-Disposition' header hints to the browser that this should be treated as an attachment, rather than (the default for 'text/plain') launching 'in-browser'.
On my system ; the browser behaviour is to ask the end-user what they want to do with the file:
This is a 'one-way' process; the resultant text editor (notepad in my case, and in most default cases I guess) is not in any way able to save the data back to the PRPC.
Cheers
John
Pegasystems Inc.
GB
The second scenario - where you launch notepad from a browser; and save the data back - would to have to be done via a (CA-signed) Java Applet / ActiveX process and is much more complicated for me to come up with I'm afraid !
(My question really should have been : what is the point in launching notepad.exe from a browser; if you can't save the data back somewhere?)
Cheers !
John
GovCIO
US
Hi Kousik,
Tried your code in IE11 and worked for me but as John mentioned we should try from server side rather than client side implementation.
Thanks,
Ravi Kumar.
Nordea
SE
Thanks John and Ravi for your support. It worked for me.