Sunday, September 13, 2009

Using Python to control a Scilab instance

This example shows how to start Scilab, pass it a file to execute, and terminate it if necessary. In this example, Scilab is not in the search path, therefore, the full path to Scilab is necessary.
This example only works on Python 2.6 or later.
"""
StartThreadForSciLab.py
"""

import subprocess

# write scilab script into a file. 
# this will be executed by Scilab

f = open('C:\\tmp\\scilabTest.sce', 'w')
cmds = """printf('hello!')
x = input("Press return to continue:","string")
exit
"""
f.write(cmds)
f.close

# start up Scilab and retain a handle to control and monitor
sciLabProcess = subprocess.Popen(
    '"C:\\Program Files\\scilab-5.1.1\\bin\\WScilex.exe" -f c:\\tmp\\scilabTest.sce ', 
    bufsize=0, 
    executable=None, 
    stdin=None, 
    stdout=None, 
    stderr=None, 
    preexec_fn=None, 
    close_fds=False, 
    shell=False, 
    cwd=None, 
    env=None, 
    universal_newlines=False, 
    startupinfo=None, 
    creationflags=0)
    
# wait for process to exit, or terminate it
while sciLabProcess.poll() is None:
    print 'still running'
    reply = raw_input("Kill process ? (type yes) ")
    if reply.strip()=='yes':
        sciLabProcess.terminate()

Using Python to start a process: Notepad as an example

This examples shows how to start a common process in windows while allowing the Python program to continue and, if needed, terminate the process.
import subprocess

notepadProcess = subprocess.Popen("Notepad")
while notepadProcess.poll() is None:
    print 'still running'
    reply = raw_input("Kill process ? (type yes) ")
    print '>>|'+reply.strip()+'|<<'
    if reply.strip()=='yes':
        print "closing process"
        notepadProcess.terminate()

Tuesday, January 13, 2009

Basic setup for dedicated service of a Ubuntu box 1) Setup automatic log in: system>administration>login window>enable automatic login ...... see http://www.inspectmygadget.com/2007/08/27/img-quickie-login-automatically-to-ubuntu/ 2) fix issue with secure wireless. Disable nm-applet in sessions manager: preference>sessions>start-up programs>disable network manager. Creat the following script: #!/bin/bash #launch useful stuff for gnome... #first unlock the default keyring... echo /usr/libexec/pam-keyring-tool -u -s #then run nm-applet in the background... nm-applet & Add this script to the start-up programs.

Automatically log into Ubuntu

see http://www.inspectmygadget.com/2007/08/27/img-quickie-login-automatically-to-ubuntu/ Basic steps: 1) system>administration>login window 2) security tab 3) enable automatic login

Monday, January 12, 2009

Accessing the Linux Machine Remotely from a PC

  1. Install putty portable. See www.portableapps.com
  2. Start putty portable.
  3. Specify linux machine and hit connect.

Ubuntu tightVNC

To setup and use a Ubuntu machine...

  1. Get tightVNC server and client using the Synaptics package manager
  2. From a terminal start the server using "$tightvncserver -nolisten tcp :1" See https://help.ubuntu.com/community/VNC
  3. To connect, a) For a PC, download http://www.tightvnc.com/ and install. Start and connect. Don't foget to specify the full name including the terminal number, e.g. "computer:1" b) For another linux box, from a terminal start the client using $tightvncclient

My favorite server configuration:

$tightvncserver -display 1280x800 -depth 32

Saturday, January 3, 2009

Getting Webware + Apache to work on Ubuntu

Useful Links:

Steps: see http://www.webwareforpython.org/WebKit/Docs/InstallGuide.html#id8

  1. Install Apache 2. The built in package installer will install the cgi-bin directory under usr/lib.
  2. Download and install Webware 1.0
  3. In ../Webware/WebKit/Adapters/wkcgi run make (I use /home/Webware/Webkit/...)
  4. copy wkcgi to usr/lib/cgi-bin/wkcgi.cgi
  5. copy WebKit.cfg to usr/lib/cgi-bin directory
  6. Install webit from webkit directory $python install.py
  7. start apache
  8. start WebKit app server by invoking WebKit/AppServer
  9. test by opening http://127.0.0.1/
  10. test by opening http://127.0.0.1/cgi-bin/wkcgi.cgi

You can stop the server by typing ^Z at the terminal.

Exploring Python Centric Web servers

Useful Links: Useful Texts: General Comments on Python Centric/Compatible Frameworks
  • Webware
  • Xitami
  • Apache
  • Zope
  • Grok