"pnuts" command takes a short but significant time to start up. This is because the command starts a Java VM every time. Therefore, the pnuts command is not suitable for frequent use of small scripts.
In Personal Server environment this problem is eliminated by a program called pserv running as a network server and a lightweight client program psh which is used on the same machine.
For security reason, pserv's service should be protected from other users. In the Personal Server environment, psh sends a cookie with the scripts every time. When pserv starts, it generates a random number, called cookie, and save it in a user's private file. psh read the number and send it to the pserv server every time.
Currently Solaris and Win32 versions are provided.
|
To start a personal server, execute pserv.bat from a DOS window or dubble click the batch file. Probably you need to change %PATH% and %PNUTS_HOME% in the pserv.bat. To stop the personal server, type Ctrl-C in the DOS window that pserv.bat opened.
When pserv starts, a subdirectory ".pnuts" is created under the directory of the "user.home" property. Then cookie file is created in it. The port number to which the server is listen and a random number are saved in the cookie file.
Since the Java property "user.home" is different from VM to VM, pserv command can accept "-home" switch to specify the base directory of the .pnuts/cookie file. If "user.home" of your JVM is different from the following standard definition, don't forget to specify '-home' option. You might want to edit the pserv.bat file to add the -home option.
platform | cookie file |
---|---|
Windows NT | C:\Winnt\Profiles\%USERNAME%\.pnuts\cookie |
Multi-user Win95/98 | C:\Windows\Profiles\%USERNAME%\.pnuts\cookie |
Single-user Win95/98 | C:\Windows\.pnuts\cookie |
|
psh command executes the specified script or expression as a Windows console application. pshw does the same as a Win32 Application.
The following variables are defined in the personal server environment.
C:\> psh test.pnut
- $cwd
- the current directory name of the client
- $args
- an array of command line arguments
The following optional steps allow you to start a server and execute scripts by double clicking.
|
pserv start command starts the service. If -port switch is not specified an unused port number is assigned.
% pserv start port=55712
When pserv starts, a subdirectory ".pnuts" is created under the directory of the "user.home" property. Then cookie file is created in it. The port number to which the server is listen and a random number are saved in the cookie file.
Since the Java property "user.home" is different between platforms (*1), pserv command can accept "-home" switch to specify the base directory of the .pnuts/cookie file.
|
psh command is the client side program of a Personal Server environment. If "-port" switch is given, it connects to the port on the local machine. Otherwise, the port number is read from the cookie file.
If -e option is given, the expression is evaluated. If script_file is given, the file is loaded. If neither script_file nor -e option is given, psh program reads scripts from the standard input.
% psh /tmp/test.pnut %
On Unix platforms, if the first line of the script starts with "#!", the line is skipped so that the script file can be executable. The variable "$cwd" is defined as the current directory of the client. The variable "$args" is defined as an array of command line arguments. The following script is an implementation of echo command.
#!/bin/env psh for (i = 1; i < $args.length; i++){ println($args[i]) }
There is no way to cancel a server-side task in the current version. When you try to quit a long running program with Ctrl-C, the server-side program will not be terminated.