[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Python CGI to Terminal Emulator

Posted on 2014-03-23
7
Medium Priority
?
668 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Several part series to implement Internet Explorer 11 Enterprise Mode
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

650 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