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
Solved

Python CGI to Terminal Emulator

Posted on 2014-03-23
7
637 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

861 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