1

I am having trouble trying to get this script to work. When I debug this code it will not read into the class or functions. The code will not execute properly. Has anyone know the problem here, Thanks

#!/home/build/test/Python-2.6.4

import os, subprocess

class mks_function:

 sandbox="new_sandbox"

 def mks_create_sandbox():  
  try:  
   retcode=call("si createsandbox" + "--no --hostname=bel --port=70 --user=user --password=1234 --populate --project=e:/project.pj --lineTerminator=lf new_sandbox", shell=True)  
   if retcode < 0:  
    print >>sys.stderr, "Child was terminated by signal", -retcode  
   else:  
    print >>sys.stderr, "Child returned", retcode  
 except OSError, e:  
    print >>sys.stderr, "Execution failed:", e  
    print "sandbox retVal="+retcode  
    print "Creating a new sandbox called "+sandbox+" "  
###############################################################
1
  • Please use the formatting features of SO to format you code so that it matches what you have in your file. It's impossible to see where the problem might be. Also, maybe post the error messages you received. Commented Dec 18, 2009 at 10:18

2 Answers 2

2

Few things to check your code

  • call should be subprocess.call
  • better use full path when you call for example, /usr/bin/si createsandbox, you can check with which si in shell
  • instead of concatenating the commands "si createsandbox" + "--no ...", please use list ["/usr/bin/si","createsandbox --no ..."]
  • you didn't import sys, but using it
  • sandbox should be self.sandbox and def mks_create_sandbox(): should be def mks_create_sandbox(self):
  • Use an IDE for example Ulipad.
Sign up to request clarification or add additional context in comments.

Comments

1

Try put as the first line:

#!/usr/bin/env python

If you really need specific version of Python, setup your environment before running.

Possible problems:

  • your code is never executed (it's like you define the class only). Use it in the file (names are misleading):

    if __name__ == '__main__': myObject = mks_function()

  • show us how are you executing the code? Have you changed the permissions to be able to run the script?

    chmod +x filename.py

  • or are you trying to start it as:

    python filename.py

1 Comment

setting up environment variables is MUCH easier in the long run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.