I am using Unix OS and I want to know how to execute a command that is executable from a different software in Python script.      I have this software installed into my system called HAL Tools and it has a command called maf2hal with two arguments which are input and output files. The path for the command is saved in my .bash_profile under PATH variable. I call the command from UNIX likewise:  [root ~]$ maf2hal inputfile outputfile   I want to call this command from a Python script. What is the statement or function that I need to use.
2579
How do you call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
37024
I need to run a (Tcl, or whatever) script on a remote Unix machine, from a (local) Windows command shell, and I want the stdout/stderr of the script to show up in the Windows CLI. The exit code would also be useful.  Is this possible using ssh (putty)? Or by any other means?  Thanks!
848
I'm writing a Python application that takes as a command as an argument, for example:  $ python myapp.py command1   I want the application to be extensible, that is, to be able to add new modules that implement new commands without having to change the main application source. The tree looks something like:  myapp/     __init__.py     commands/         __init__.py         command1.py         command2.py     foo.py     bar.py   So I want the application to find the available command modules at runtime and execute the appropriate one.  Python defines an __import__ function, which takes a string for a module name:     __import__(name, globals=None, locals=None, fromlist=(), level=0)      The function imports the module name, potentially using the given globals and locals to determine how to interpret the name in a package context. The fromlist gives the names of objects or submodules that should be imported from the module given by name.       Source:    So currently I have something like:  command = sys.argv[1] try:     command_module = __import__("myapp.commands.%s" % command, fromlist=["myapp.commands"]) except ImportError:     # Display error message  command_module.run()   This works just fine, I'm just wondering if there is possibly a more idiomatic way to accomplish what we are doing with this code.  Note that I specifically don't want to get in to using eggs or extension points. This is not an open-source project and I don't expect there to be "plugins". The point is to simplify the main application code and remove the need to modify it each time a new command module is added.
93899
I have a Python script that needs to execute an external program, but for some reason fails.  If I have the following script:  import os; os.system("C:\\Temp\\a b c\\Notepad.exe"); raw_input();   Then it fails with the following error:     'C:\Temp\a' is not recognized as an internal or external command, operable program or batch file.   If I escape the program with quotes:  import os; os.system('"C:\\Temp\\a b c\\Notepad.exe"'); raw_input();   Then it works. However, if I add a parameter, it stops working again:  import os; os.system('"C:\\Temp\\a b c\\Notepad.exe" "C:\\test.txt"'); raw_input();   What is the right way to execute a program and wait for it to complete? I do not need to read output from it, as it is a visual program that does a job and then just exits, but I need to wait for it to complete.  Also note, moving the program to a non-spaced path is not an option either.    This does not work either:  import os; os.system("'C:\\Temp\\a b c\\Notepad.exe'"); raw_input();   Note the swapped single/double quotes.  With or without a parameter to Notepad here, it fails with the error message     The filename, directory name, or volume label syntax is incorrect.
77127
I can seem to run scripts (.sh) with and without them being set as executable. So where exactly this matters?
47219
Possible Duplicate:          I'm trying to make a Mark as executable command for the right click in nautilus for a faster work flow. I came up with this script:  #! /bin/bash for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do gksudo "chmod +x $file" &amp; done   How do I get this to work though. I currently have a .sh file and have no idea where to put it.
76879
I want to execute something in a linux shell under a few different conditions, and be able to output the execution time of each execution.  I know I could write a perl or python script that would do this, but is there a way I can do it in the shell? (which happens to be bash)
6208
I'm trying to run an executable (testdisk) but double click doesn't work. The only way is to run:  sudo ./testdisk   from terminal. But I'd like to open executables with double click in future. How can I do this?
105352
I want to be able to run Python commands from the Windows CMD. However, if I don't specify Python's full path for each command, I get an error saying "Python is not recognized as an internal or external command, operable program or batch file."  How do I add Python to the Windows PATH permanently?
79136
So I'm in Linux and I want to have a program accept arguments when you execute it from the command line.  For example,   ./myprogram 42 -b -s  So then the program would store that number 42 as an int and execute certain parts of code depending on what arguments it gets like -b or -s.
50616
So, I thought I had a good understanding of this, but just ran a test (in response to a conversation where I disagreed with someone) and found that my understanding is flawed...  In as much detail as possible what exactly happens when I execute a file in my shell? What I mean is, if I type: ./somefile some arguments into my shell and press return (and somefile exists in the cwd, and I have read+execute permissions on somefile) then what happens under the hood?  I thought the answer was:   The shell make a syscall to exec, passing the path to somefile The kernel examines somefile and looks at  of the file to determine if it is a format the processor can handle If the magic number indicates that the file is in a format the processor can execute, then   a new process is created (with an entry in the process table) somefile is read/mapped to memory. A stack is created and execution jumps to the entry point of the code of somefile, with ARGV initialized to an array of the parameters (a char**, ["some","arguments"])  If the magic number is a  then exec() spawns a new process as above, but the executable used is the interpreter referenced by the shebang (e.g. /bin/bash or /bin/perl) and somefile is passed to STDIN If the file doesn't have a valid magic number, then an error like "invalid file (bad magic number): Exec format error" occurs   However someone told me that if the file is plain text, then the shell tries to execute the commands (as if I had typed bash somefile). I didn't believe this, but I just tried it, and it was correct. So I clearly have some misconceptions about what actually happens here, and would like to understand the mechanics.  What exactly happens when I execute a file in my shell? (in as much detail is reasonable...)
80763
Typical Unix/Linux programs accept the command line inputs as an argument count (int argc) and an argument vector (char *argv[]). The first element of argv is the program name - followed by the actual arguments.   Why is the program name passed to the executable as an argument? Are there any examples of programs using their own name (maybe some kind of exec situation)?
59061
I know that external commands are run in the shell by creating a separate process, but what exactly happens when a built-in command is run in a shell?  Are they executed as a function,  or does the shell create a new thread to execute them?
70475
When loading a python virtual environment I need to run:  source venv/bin/activate   I want an alias for this command because I have to run it all the time. So I put the following in a file called "load.sh":  #!/bin/bash source venv/bin/activate   And ran  chmod +x load.sh   However, now when I run ./load.sh there is no effect. My suspicion is that the word "source" may be the issue. But I don't know. Any ideas? Thanks.
80321
I've got a Perl script that needs to execute another Perl script. This second script can be executed directly on the command line, but I need to execute it from within my first program. I'll need to pass it a few parameters that would normally be passed in when it's run standalone (the first script runs periodically, and executes the second script under a certain set of system conditions).  Preliminary Google searches suggest using backticks or a system() call. Are there any other ways to run it? (I'm guessing yes, since it's Perl we're talking about :P ) Which method is preferred if I need to capture output from the invoked program (and, if possible, pipe that output as it executes to stdout as though the second program were invoked directly)?  (Edit: oh, now SO suggests some related questions.  is close, but not exactly the same as what I'm asking. The second program will likely take an hour or more to run (lots of I/O), so I'm not sure a one-off invocation is the right fit for this.)
7361
How could I execute a script in Shell when a shortcut key is pressed.   Essentially what I need is when a shortcut key is pressed the script should read from a file and display that content in the terminal.
117882
I tried to use at from within a script of mine and it prints:       warning: commands will be executed using /bin/sh   How would I use different shell if I wanted?