RunAProgram: Difference between revisions
m link fix |
mNo edit summary |
||
Line 15: | Line 15: | ||
</PRE> | </PRE> | ||
* | * [[AccuTerm]]: | ||
To execute a command and return to PICK | To execute a command and return to PICK/BASIC immediately: | ||
<PRE> | <PRE> | ||
PRINT CHAR(27):CHAR(2):"<":command:CHAR(13) | PRINT CHAR(27):CHAR(2):"<":command:CHAR(13) | ||
</PRE> | </PRE> | ||
To execute a command and wait for the command to terminate before returning to PICK | To execute a command and wait for the command to terminate before returning to PICK/BASIC: | ||
<PRE> | <PRE> | ||
PRINT CHAR(27):CHAR(2):">":command:CHAR(13) | PRINT CHAR(27):CHAR(2):">":command:CHAR(13) | ||
Line 62: | Line 62: | ||
Doit is a small utility program that installs a tray applet on the client. The server sends it the path of a file to open. | Doit is a small utility program that installs a tray applet on the client. The server sends it the path of a file to open. | ||
http://www.chiark.greenend.org.uk/~sgtatham/doit/ | http://www.chiark.greenend.org.uk/~sgtatham/doit/ | ||
==== 2) Install rcmd ==== | ==== 2) Install rcmd ==== | ||
Line 70: | Line 69: | ||
Either from the windows resource kit, or purchase it from mks. You can then issue an rcmd from the unix side. | Either from the windows resource kit, or purchase it from mks. You can then issue an rcmd from the unix side. | ||
http://www.dynawell.com/support/ResKit/winnt.asp | http://www.dynawell.com/support/ResKit/winnt.asp | ||
http://www.mkssoftware.com/support/kb/faqs.asp?product=Toolkit&type=tech#art140 | http://www.mkssoftware.com/support/kb/faqs.asp?product=Toolkit&type=tech#art140 | ||
==== 3) Install or turn on a telnet server ==== | ==== 3) Install or turn on a telnet server ==== | ||
W2K/XP come with a telnet server, or you can purchase one. Then use http://expect.nist.gov to script the login/command process. | |||
http://www.goodtechsys.com/ | http://www.goodtechsys.com/ | ||
Just like | ==== 4) Install an SSH server ==== | ||
Just like Telnet, only secure! | |||
http://tech.erdelynet.com/cygwin-sshd.html | http://tech.erdelynet.com/cygwin-sshd.html | ||
==== 5a) Write a small server program ==== | ==== 5a) Write a small server program ==== | ||
Line 97: | Line 94: | ||
Recent U2 products can create socket connections from basic and connect to the server. Sample code for this is at [[BasicSocketClient]]. | Recent U2 products can create socket connections from basic and connect to the server. Sample code for this is at [[BasicSocketClient]]. | ||
Here's a stripped down example of a server in | Here's a stripped down example of a server in [http://www.python.org Python]: | ||
urlserver.py | urlserver.py | ||
<PRE> | <PRE> | ||
import | import SocketServer | ||
import os | import os | ||
class | class UrlHandler(SocketServer.StreamRequestHandler): | ||
def handle(self): | def handle(self): | ||
url=self.rfile.readline(512) | url=self.rfile.readline(512) | ||
Line 110: | Line 107: | ||
os.system("start "+url) | os.system("start "+url) | ||
server= | server=SocketServer.TCPServer( ('', 79), UrlHandler) | ||
server.serve_forever() | server.serve_forever() | ||
</PRE> | </PRE> | ||
Line 116: | Line 113: | ||
On the pc, type "python urlserver.py" to start the server up, then from another machine, "telnet pc-address 79" and then type the url to go to - the client will open up a browser and go to that address. | On the pc, type "python urlserver.py" to start the server up, then from another machine, "telnet pc-address 79" and then type the url to go to - the client will open up a browser and go to that address. | ||
==== 5b) ...and here's another in | ==== 5b) ...and here's another in VBScript ==== | ||
urlserver.vbs | urlserver.vbs | ||
Line 128: | Line 125: | ||
On Error Resume Next | On Error Resume Next | ||
Err.Number=0 | Err.Number=0 | ||
Set oSck=WScript. | Set oSck=WScript.CreateObject("MSWinsock.Winsock","s_") | ||
Select Case Err.Number | Select Case Err.Number | ||
Case 0 | Case 0 | ||
Line 134: | Line 131: | ||
echo "No licence found. Install Visual Studio" | echo "No licence found. Install Visual Studio" | ||
case &H80020009 | case &H80020009 | ||
echo " | echo "ActiveX Winsock not in the registry, check if installed or use regsvr32" | ||
Case else | Case else | ||
echo "Error " & Err.Number & " - &H" & Hex(Err.Number) & " - " & Err.Description | echo "Error " & Err.Number & " - &H" & Hex(Err.Number) & " - " & Err.Description | ||
Line 140: | Line 137: | ||
On Error Goto 0 | On Error Goto 0 | ||
oSck. | oSck.LocalPort=79 | ||
oSck.Listen | oSck.Listen | ||
echo "Listening on port " & oSck. | echo "Listening on port " & oSck.LocalPort | ||
Do | Do | ||
' Sleep for 2 seconds | ' Sleep for 2 seconds | ||
Line 152: | Line 149: | ||
End Sub | End Sub | ||
Sub | Sub s_ConnectionRequest(Byval requestID) | ||
oSck.Close | oSck.Close | ||
echo oSck. | echo oSck.RemoteHostIP & " - Connection request:" & requestID | ||
oSck.Accept requestID | oSck.Accept requestID | ||
End Sub | End Sub | ||
Line 169: | Line 166: | ||
End Sub | End Sub | ||
Sub s_Error( | Sub s_Error(ByVal N, D, ByVal C, ByVal S, ByVal F, ByVal H, Y) | ||
echo "Error" & N & " - " & D | echo "Error" & N & " - " & D | ||
oSck.Close | oSck.Close | ||
Line 175: | Line 172: | ||
End Sub | End Sub | ||
Sub | Sub s_DataArrival(Byval b) | ||
Dim S,sh | Dim S,sh | ||
S="" | S="" | ||
oSck. | oSck.GetData S | ||
S=left(S,len(S)-2) | S=left(S,len(S)-2) | ||
S=left(S,512) | S=left(S,512) | ||
Line 194: | Line 191: | ||
</PRE> | </PRE> | ||
On the | On the PC, type "cscript urlserver.vbs" to start the server up, then from another machine, "telnet pc-address 79" and then type the url to go to - the client will open up a browser and go to that address. | ||
==== 6) Have a polling program on the client ==== | ==== 6) Have a polling program on the client ==== | ||
Line 201: | Line 198: | ||
<PRE> | <PRE> | ||
Private Sub | Private Sub Form_Load() | ||
txtScheduleNum.Enabled = False | |||
cboCategory.Enabled = False | cboCategory.Enabled = False | ||
cmdOK.Enabled = False | cmdOK.Enabled = False | ||
Line 211: | Line 208: | ||
Me.Show | Me.Show | ||
' Start the poll right away | ' Start the poll right away | ||
Timer1_Timer | |||
End Sub | End Sub | ||
Private Sub [[Timer1_Timer]]() | Private Sub [[Timer1_Timer]]() | ||
TxtLog.ForeColor = vbBlack | |||
LogMsg "Checking c:\batch" | |||
Set fso = | Set fso = CreateObject("Scripting.FileSystemObject") | ||
Set dir = fso. | Set dir = fso.GetFolder("C:\BATCH") | ||
For Each file In dir.Files | For Each file In dir.Files | ||
If LCase(Right(file.Name, 3)) = "pdf" Then | If LCase(Right(file.Name, 3)) = "pdf" Then | ||
Timer1.Enabled = False | Timer1.Enabled = False | ||
TxtLog.Enabled = False | |||
fstr = file.Name | fstr = file.Name | ||
hpsname = Left(fstr, Len(fstr) - 3) & "hps" | hpsname = Left(fstr, Len(fstr) - 3) & "hps" | ||
justname = Left(fstr, Len(fstr) - 3) | justname = Left(fstr, Len(fstr) - 3) | ||
LogMsg fstr | |||
Label1.Enabled = True | Label1.Enabled = True | ||
Label3.Enabled = True | Label3.Enabled = True | ||
Line 234: | Line 231: | ||
cmdPreview.Enabled = True | cmdPreview.Enabled = True | ||
' Enable some controls and do something with the file | ' Enable some controls and do something with the file | ||
txtScheduleNum.SetFocus | |||
Exit For | Exit For | ||
End If | End If | ||
Line 244: | Line 241: | ||
(Ad) | (Ad) | ||
The following link goes to the Nebula R&D forum where an offering is discussed and a link is provided to a blog entry for more information. As of the time of this writing the software is fully usable but is not being offered as a product simply for lack of demand. That situation can change with a compelling business case. http://nebula-rnd.com/forum/index.php/topic,51.0.html | The following link goes to the Nebula R&D forum where an offering is discussed and a link is provided to a blog entry for more information. As of the time of this writing the software is fully usable but is not being offered as a product simply for lack of demand. That situation can change with a compelling business case. http://nebula-rnd.com/forum/index.php/topic,51.0.html | ||
( | (/Ad) | ||
A general description of this approach, not specific to the Nebula solution, would be to write a PC program in your favourite language (.Net, Java, Flex for example), that runs on the PC and makes periodic calls to a Pick program using whatever technology makes sense for your Pick variety. In the U2 world, this would be [[UniObjects]], though a web services call that hides the connection details from the client, and be much more likely to work through firewalls, would make more sense. | A general description of this approach, not specific to the Nebula solution, would be to write a PC program in your favourite language (.Net, Java, Flex for example), that runs on the PC and makes periodic calls to a Pick program using whatever technology makes sense for your Pick variety. In the U2 world, this would be [[UniObjects]], though a web services call that hides the connection details from the client, and be much more likely to work through firewalls, would make more sense. | ||
Line 254: | Line 251: | ||
<strong>TODO</strong>: Expand on this topic with info about D3 compile to executable with G option, UDT, notes about unique jBASE exe/dll design... | <strong>TODO</strong>: Expand on this topic with info about D3 compile to executable with G option, UDT, notes about unique jBASE exe/dll design... | ||
Latest revision as of 22:05, 15 May 2015
HomePage>>HowTos>>RunAProgram
The problem: you want a program to run on a windows PC as a result of something that happens on your Windows or Unix-based server. It's usually less of an issue to have a Unix server run something on a Unix client, or Windows server to Windows client - there's plenty of built in ways for that to work. So we'll just consider a Windows PC with a network connection (LAN,WAN or VPN) to a Unix server.
For this to work "something", some program, has to be running on the PC.
0) TerminalEmulators
The most common "something" is a terminal emulator and they pretty much all allow you to send an escape sequence and fire off a program. If you want the program to run in response to something the user did on the server, this is the most straightforward way to do it. Also, if you have a serial connection, this is probably the only option.
- wIntegrate:
Use the WIN.PCRUN command installed on the server, CALL WIN.PCRUN(COMMAND,ARGS)
To execute a command and return to PICK/BASIC immediately:
PRINT CHAR(27):CHAR(2):"<":command:CHAR(13)
To execute a command and wait for the command to terminate before returning to PICK/BASIC:
PRINT CHAR(27):CHAR(2):">":command:CHAR(13)
See AccuTerm help for details: From the Help Introduction, see AccuTerm Programming. Also see Help on Object Bridge.
More examples are at AccuTermFileTransfer.
?
- Powerterm:
PRINT CHAR(27):"$tS":COMMAND:CHAR(27):"\"
- Netterm:
Start/run the program specified by COMMAND.
CRT CHAR(27):"[]":COMMAND:CHAR(27):"[1*
Send the URL to the client's WWW browser for processing.
CRT CHAR(27):'[]':URL:CHAR(27):'[0*'
Start/run the program specified by COMMAND and wait till it terminates. COMMAND can contain both the program to run and command line arguments.
CRT CHAR(27):"[]":COMMAND:CHAR(27):"[9*"
Start the program associated with the extension contained within FILENAME.
CRT CHAR(27):"[]":FILENAME:CHAR(27):"[12*
1) Doit
Doit is a small utility program that installs a tray applet on the client. The server sends it the path of a file to open.
http://www.chiark.greenend.org.uk/~sgtatham/doit/
2) Install rcmd
Either from the windows resource kit, or purchase it from mks. You can then issue an rcmd from the unix side.
http://www.dynawell.com/support/ResKit/winnt.asp
http://www.mkssoftware.com/support/kb/faqs.asp?product=Toolkit&type=tech#art140
3) Install or turn on a telnet server
W2K/XP come with a telnet server, or you can purchase one. Then use http://expect.nist.gov to script the login/command process.
4) Install an SSH server
Just like Telnet, only secure!
http://tech.erdelynet.com/cygwin-sshd.html
5a) Write a small server program
Have the program listen on a predefined port. There are obvious security issues here, but with a little handwaving we can move past them :-)
Recent U2 products can create socket connections from basic and connect to the server. Sample code for this is at BasicSocketClient.
Here's a stripped down example of a server in Python:
urlserver.py
import SocketServer import os class UrlHandler(SocketServer.StreamRequestHandler): def handle(self): url=self.rfile.readline(512) print "opening "+url os.system("start "+url) server=SocketServer.TCPServer( ('', 79), UrlHandler) server.serve_forever()
On the pc, type "python urlserver.py" to start the server up, then from another machine, "telnet pc-address 79" and then type the url to go to - the client will open up a browser and go to that address.
5b) ...and here's another in VBScript
urlserver.vbs
Option Explicit ' Heavily cribbed from the amazing 4K webserver at: ' http://www.interclasse.com/scripts/4KWebServer.php Dim oSck On Error Resume Next Err.Number=0 Set oSck=WScript.CreateObject("MSWinsock.Winsock","s_") Select Case Err.Number Case 0 case &H80040112 echo "No licence found. Install Visual Studio" case &H80020009 echo "ActiveX Winsock not in the registry, check if installed or use regsvr32" Case else echo "Error " & Err.Number & " - &H" & Hex(Err.Number) & " - " & Err.Description End Select On Error Goto 0 oSck.LocalPort=79 oSck.Listen echo "Listening on port " & oSck.LocalPort Do ' Sleep for 2 seconds WScript.sleep 2000 Loop Sub echo(S) WScript.Echo Now & " " & S End Sub Sub s_ConnectionRequest(Byval requestID) oSck.Close echo oSck.RemoteHostIP & " - Connection request:" & requestID oSck.Accept requestID End Sub Sub s_Close oSck.Close echo "closed - re-listening" oSck.Listen End Sub Sub s_[[SendComplete]] oSck.close oSck.Listen End Sub Sub s_Error(ByVal N, D, ByVal C, ByVal S, ByVal F, ByVal H, Y) echo "Error" & N & " - " & D oSck.Close oSck.Listen End Sub Sub s_DataArrival(Byval b) Dim S,sh S="" oSck.GetData S S=left(S,len(S)-2) S=left(S,512) echo S set sh = createobject("wscript.shell") on error resume next sh.run "cmd /c start " & S on error goto 0 oSck.Close oSck.Listen End Sub
On the PC, type "cscript urlserver.vbs" to start the server up, then from another machine, "telnet pc-address 79" and then type the url to go to - the client will open up a browser and go to that address.
6) Have a polling program on the client
If the client and the server share access to a directory (via samba or NFS for example), the server can drop a file in the common directory and a program running on the client can watch for new files. When one is found it can read the file and perform some action based on the contents. Here's a VB example:
Private Sub Form_Load() txtScheduleNum.Enabled = False cboCategory.Enabled = False cmdOK.Enabled = False cmdPreview.Enabled = False Label1.Enabled = False Label3.Enabled = False Me.Show ' Start the poll right away Timer1_Timer End Sub Private Sub [[Timer1_Timer]]() TxtLog.ForeColor = vbBlack LogMsg "Checking c:\batch" Set fso = CreateObject("Scripting.FileSystemObject") Set dir = fso.GetFolder("C:\BATCH") For Each file In dir.Files If LCase(Right(file.Name, 3)) = "pdf" Then Timer1.Enabled = False TxtLog.Enabled = False fstr = file.Name hpsname = Left(fstr, Len(fstr) - 3) & "hps" justname = Left(fstr, Len(fstr) - 3) LogMsg fstr Label1.Enabled = True Label3.Enabled = True cboCategory.Enabled = True cmdOK.Enabled = True cmdPreview.Enabled = True ' Enable some controls and do something with the file txtScheduleNum.SetFocus Exit For End If Next End Sub
7) Consider using a solution created specifically to solve the problem
(Ad) The following link goes to the Nebula R&D forum where an offering is discussed and a link is provided to a blog entry for more information. As of the time of this writing the software is fully usable but is not being offered as a product simply for lack of demand. That situation can change with a compelling business case. http://nebula-rnd.com/forum/index.php/topic,51.0.html (/Ad)
A general description of this approach, not specific to the Nebula solution, would be to write a PC program in your favourite language (.Net, Java, Flex for example), that runs on the PC and makes periodic calls to a Pick program using whatever technology makes sense for your Pick variety. In the U2 world, this would be UniObjects, though a web services call that hides the connection details from the client, and be much more likely to work through firewalls, would make more sense.
Note: this is not exactly the problem we are trying to solve on this page. The problem is "how do I run a program on the client side, on demand from a Pick program?" The polling solutions presented suffer from a lag between something happening on the server and a program running on the client.
Running a program on the server from outside
Connectivity to MV is discussed many places in this wiki and any language can be used to execute BASIC business rules and return a result. A unique freeware program called MV Exec uses mv.NET to run any query, any command, any program on a MV server from any PC.
TODO: Expand on this topic with info about D3 compile to executable with G option, UDT, notes about unique jBASE exe/dll design...