?
Solved

Python CGI to Terminal Emulator

Posted on 2014-03-23
7
Medium Priority
?
663 Views
Last Modified: 2014-04-14
I have a Python CGI that needs to send a lot of form data to a terminal emulator.  I was attempting to use Windows Script Host to do this, which works fine from the command line, but does not work through the CGI.  Is there an alternative way to accomplish this task?  Is it also possible that this is a web browser permissions issue?
0
Comment
Question by:front71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 9

Expert Comment

by:techtonik
ID: 39955212
It is hard to say what you need to do exactly and what fails (how it 'does not work') without some bits of code. You may try to use CGi server written in Python for debugging. It may be easier to see where the bug happens. Python 2 ships with CGI server that can be executed with:

python -m CGIHTTPServer

Open in new window

0
 

Author Comment

by:front71
ID: 39956298
Thank you for replying, techtonik.  There is only one instance of Notepad running.  I'm using Python 2.7.3 64-bit, Firefox, and IIS on a Windows 7 machine.  Below is my entire code.  I hope that it clarifies things for you.

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys, os
import cgi
import cgitb

import pythoncom

import win32api
import win32com.client

def testFcn():
   ok = False

   try:
      shell = win32com.client.Dispatch('WScript.Shell')
      ok = shell.AppActivate('Notepad')
      win32api.Sleep(500)
      shell.SendKeys("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
      win32api.Sleep(500)
      shell.SendKeys("{ENTER}")
      win32api.Sleep(500)

   except pythoncom.com_error,(hr,msg,exc,arg):
      myStr += "Error"
     
   if ok:
      myStr = "Success"
   else:
      myStr = "Failed"

   return myStr

#-------------------------------------------------------------------------------
# MAIN
#-------------------------------------------------------------------------------
aStr = testFcn()

print """
<!DOCTYPE html>
<html>
   <head>
      <title> Test </title>
   </head>
   <body> {0} </body>
</html>
""".format(aStr)
0
 
LVL 9

Expert Comment

by:techtonik
ID: 39956751
Wow. I am pretty sure that for security reasons web servers should not allow to call win32com stuff in CGI scripts. What webserver do you use? Is there a stack trace or something? What happens if you don't catch the exception?
0
Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

 

Author Comment

by:front71
ID: 39962558
It's an IIS box.  The script definitely works via terminal / command line, just not in a web browser.
0
 

Accepted Solution

by:
front71 earned 0 total points
ID: 39989110
I was able to accomplish my task by going through ActiveX.  Thank you mods for trying to help.
0
 

Author Comment

by:front71
ID: 39989115
Please close this question since I was able to solve it on my own.
0
 

Author Closing Comment

by:front71
ID: 39998531
I was able to solve it with a different method and no one suggested anything that was helpful.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question