w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Python executes mysteriously other phantom script
In Python the import path contains . (working directory). Importing a module basically means executing it. That is why your importing of queue from urlfilter.py resulted in queue being executed. To avoid accidental execution of scripts by importing, you can check the __name__ variable for the value '__main__'. if __name__ == '__main__': do_not_execute_this_during_import()

Categories : Python

vim - python-mode - is there a way to send a Ctrl+C to a running script in pymode?
This is one of the problems recently discussed in vim-dev and in some other topics. This behavior requires patching vim source to have eventloop in a separate thread, but there is no patch for this yet. Currently there is no way to do this. Some running python scripts may be interrupted by sending a SIGINT, but not all.

Categories : Vim

How to capture the exit code of a shell script in a perl script?
You can check the exit code of another process with the child error variable $?. For example: system("perl foo.pl"); my $exit_val = $? >> 8; # now contains the exit value of the perl script Read the documentation for more info.

Categories : Perl

Capture value from shell script and use it in Python without using subprocess
Try commands module for py2.3.4, note that this module has been deprecated since py2.6: Use commands.getoutput: import commands answer = commands.getoutput('./a.sh')

Categories : Python

Invoke python script from another python script and set execution directory of the executed script
You could use cwd parameter, to run scriptB in its directory: import os from subprocess import check_call check_call([scriptB], cwd=os.path.dirname(scriptB))

Categories : Python

How can I capture 'Ctrl-D' in python interactive console?
Use raw_input (Use input in Python 3.x). Pressing Ctrl+D will cause EOFError exception. try: raw_input() except EOFError: pass UPDATE Use atexit - Exit handlers: import atexit def quit_gracefully(): print 'Bye' atexit.register(quit_gracefully)

Categories : Python

how to pass variable from python to shell script when shell script is getting called inside python script
You can: Step through the list, and then call mail.sh once for each file. This is the most reliable way. Convert the items in the list to a space delimited string, and then pass it in to mail.sh (assuming mail.sh is setup correctly, it should accept multiple arguments). What you cannot do is pass ['a.txt','b.txt','c.txt'] wholesale to the script.

Categories : Python

On Mac, how to create a drag & drop app for a python script where the script name rather than Python shows in the MenuBar (etc.)?
I have an answer to my question, but I am hoping that someone can come up with something less complex. The solution I came up with was a Python script to create an AppleScript (ugh!), compile it into a bundle and then modify the bundle to change the allowed file extension(s), the icon and so on. I did not find a way to get drag-and-drop working when starting a wxpython script, without an AppleScript (or using py2app) and I could not get the AppleScript to work in a bundle I created, I had to use osacompile to create the bundle for me. I like better the approach here or here, where one creates the plist file "by hand" rather than than modify an externally created one as I do here, but the script below does do the job. #!/usr/bin/env python '''This script creates an AppleScript app to

Categories : Python

Script file that executes other scripts
You can have scripts execute in order by chaining the command with && && makes sure the first command has completed before moving onto the other sin the chains. As opposed to & which will execute them all even if the prior ones fail. first.sh echoes I am First second.sh echoes I am Second Command sh first.sh && sh second.sh Output I am First I am Second You can tie this into a cron job if you wish to have it execute at certains times etc.

Categories : Shell

Using the rubypython gem in ruby on rails, how do you call a python script from the lib folder?
I know Python pretty well, but I've hardly ever used Ruby... There are several things wrong here: Python imports are done for module names; you are trying to import a filename instead. Normally, you'd add the directory to the #{Rails.root}/lib directory to the Python module search path (either with the PYTHONPATH environment variable or by manipulating the sys.modules list from Python code), but you are trying to import the setup script here. You'd run python setup.py install to install the library. Or, much better, use pip or easy_install to install the package for you. colorific is a command-line utility. It doesn't appear to provide an API to import. I'd not use a Ruby-to-Python bridge here, just run the tool using the Ruby equivalent of the Python subprocess module; as a separate

Categories : Python

Tkinter bind executes immediately when script is run
searchforticket(ticketfieldentry.get() cause immediate call. Change as follow: ticketfieldentry.bind("<Double-Button-1>", lambda e: searchforticket(ticketfieldentry.get()))

Categories : Python

JQuery script on an Asp.Net Web User Control Executes More Than Once
Try to change your javascript as follows: <script type="text/javascript"> function slideToggle(e, ui) { debugger; //find the right control to slideToggle var ct = e.currentTarget; var controlHolder = ct.parentNode; //up the dom one element $(controlHolder).find(".expandableContent").slideToggle(500); //back down the dom to the element we want to animate } $(document).ready(function () { //find the right control to hide var pare = $('.helpControlHolder'); pare.find(".expandableContent").hide(); }); $(function(){ $(".expandableHeading").click(function (e, ui) { e.preventDefault(); slideToggle(e, ui); }); }); </script> Hope it helps.

Categories : Jquery

Jenkins runs imported python script before main python script
The child process flushes its output buffers on exit but the prints from the parent are still in the parent's buffer. The solution is to flush the parent buffers before running the child: print("Starting script...") sys.stdout.flush() build.run()

Categories : Python

coverage.py does not cover script if py.test executes it from another directory
This turned out to be a problem of relative paths confusing coverage when the measured script is run from another directory. Coverage result files ended up in that directory, instead of the root directory of the project. To solve this, I stopped using pytest-cov, and used pure coverage instead. I used full paths instead of relative paths wherever relevant. So, e.g. define the environment variable necessary to enable subprocess coverage via export COVERAGE_PROCESS_START=/full/path/to/.coveragerc. In the .coveragerc, the coverage result file is specified via [run] data_file = /full/path/to/.coverage and any --source and --include options should use full paths, too. Then it was possible to get correct coverage measurement.

Categories : Python

Mini-Game Help 2- Executes same part of script after Raw_input
Your problem is in the if random.randrange == some_range checks. Actually, your code has several problems: First, you need to actually call the randrange function, and it needs at least one parameter: the stop value for your range (which defaults to starting at 0). See the randrange documentation for details. Second, randrange() returns a number, but you're comparing its result to a list. This will always be False: in Python, 3 and [3] are not the same value. What I suspect you want is to check if your random value is contained in the list. One way would be if random_value in some_range, because the in operator searches a list to see if it contains the value you passed in. But this would be slow on really large ranges; a much better approach would be to stop using ranges and start using

Categories : Python

Calling code after jQuery getScript executes the script
You should be able to do this quite easily using getJSON. http://api.jquery.com/jQuery.getJSON/ Something similar to this should do the trick: $.getJSON( url , function(data) { //Do something with data here alert(data); }); EDIT: The answer from the link below that I find most interesting is this one: $.ajax({ url: url, dataType: 'script', success: success, async: false }); It seems that disabling the asynchronous part of ajax will execute the script first, then the callback afterwords, instead of doing them synchronously.

Categories : Jquery

curl CURLOPT_TIMEOUT doesnt works, script executes forever
That's not the cURL problem. While Website is UP - Request Status Gets 200(OK) and Script executes Fine But While Website is DOWN - The AJAX Request keeps sending/waiting for request until it gets 200(OK) Status. Try Avoiding AJAX in this case and use PHP to send cURL Request.

Categories : PHP

undesired behaviour: makefile executes shell script while parsing
They're technically not built as the makefile is parsed. See the GNU make manual, section How Makefiles are Remade. Once make finishes parsing all the makefiles, it will perform a pass where it makes sure that all the included makefiles are up to date, by treating them all as if they were targets and trying to rebuild them. That's what you're seeing. If any makefile has changed, then make will re-execute itself from scratch so it can re-read the contents of the updated makefiles. The solution you have (where you check for the clean target, and any other targets you don't want to force a rebuild of makefiles, and if it's found you either don't do the include or you don't provide the rules to rebuild the makefiles) is the recommended solution. Remember that rules like clean, all, etc.

Categories : Shell

Orphan Child (ksh Shell Script not terminating first upon CTRL-X)
Note: Launcher is broken and should be fixed. Thus, any "solution" will be a hack. One thought is to check $PPID in various places in the script. If it is set to 1 (init), then exit the script. I don't understand the use of control-X. That is not going to generate any tty signal. I guess that is what you want. Perhaps the tty is also in raw mode. But you might consider hooking control-X up to one of the various tty signals like SIGINT. e.g. stty intr ^X but you will also need to remember to unset it with stty intr ^C Last, you could wrap the script in a script and use the technique to kill the child and exit. e.g. (untested) #!/bin/ksh # launch original program in background /path/to/real/program "$@" & # get child's pid child=$! while : ; do # when we become an orphan

Categories : Bash

sys module giving different output when running Python script through IDLE and by double-clicking the script
print os.path.dirname(sys.executable) is what you should use. When you click it it is probably running through python.exe so you are removing the extra char from the w.

Categories : Python

how to call a python script inside another python script where both in the same directory?
In script1.py place this: def main(): do something if __name__ == "__main__": main() In script2.py: import script1 if condition: script1.main()

Categories : Python

Redirect output of a .bat file run by a python script to GUI, and making that script into EXE
You could use the subprocess module to call your script Example calling the 'ls' command on Linux: >>> from subprocess import call >>> call(['ls', '-l']) total 0 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file1 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file2 -rw-rw-r-- 1 user group 0 Jun 17 18:37 file3 0

Categories : Python

Cron not running Python script is script not in home folder
cron is running crontab(5) entries from the home directory of the user. You need to change appropriately the directory i.e. to call the chdir(2) syscall (either thru the cd shell builtin, or inside your python script using os.chdir). You should query the current directory (using getcwd(3), or the pwd command, or the os.getcwd in Python) in your script. Also check your PATH if running commands.

Categories : Python

dump files from bash script in different directory from where python script ran it
You should change directory within the same command: cmd = "/path/to/executable/executable" outputdir = "/path/to/output/" subprocess.call("cd {} && {}".format(outputdir, cmd), shell=True)

Categories : Python

How do scan a script for return values from a upper script in python?
Don't invoke a Python script from a Python script by using system, which spawns a whole other interpreter. Just import it. Like this: import ToBuildOrNot needsBuild = ToBuildOrNot.run() # or whatever you call your top-level function Since ToBuildOrNot.py is a script now, make sure the "main" function is protected so it doesn't execute automatically on import. Most people do it this way in Python: What does <if __name__=="__main__":> do?

Categories : Python

error with global name when running a script from another script - python
This is a pretty interesting problem. First a quick workaround, you can provide dictionaries to use as the local and global namespace when calling execfile(), using an empty dictionary for globals works fine: # test_fun1.py a = 1 def test1(): print a execfile('test_fun2.py', {}) test1() Alternatively, if you want the code to execute within the global scope of your module you can use globals() instead of {}. Now on to why this isn't working... from the documentation on execfile(): If both dictionaries are omitted, the expression is executed in the environment where execfile() is called. Here "both dictionaries" is referring to the optional globals and locals arguments to execfile(). In this case "the environment where execfile() is called" is the local scope of the fun

Categories : Python

How run a Python script from another script and get resulting global dict?
Importing a module executes the code at the top level, and that module's "global" namespace gets imported as the name of the module james@bodacious:~$cat test.py def func(): pass myname = "michael caine" print "hello, %s" % myname james@bodacious:~$python Python 2.7.5 (default, Jul 12 2013, 18:42:21) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import test hello, michael caine >>> dir(test) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'func', 'myname'] >>> if the code you want to be run is at the top level of the file, just importing the module will execute the code and give you access to its "global" namespace all in one convenient package.

Categories : Python

ImportError when calling python script via a shell script
I had a similar problem. It turned out that in my bash script I was running the Python script with a different version of Python than I was on the command line (my env was set up with virtualenv on Python 2.7 but I was calling the script with Python3 from the bash script). There is nothing in your snippets indicating this is the case but it is worth checking to make sure that the Python versions match up.

Categories : Python

When running Python's pdb as a script, how do I autostart the script?
that's probably not the way to do to it. you should modify/extend the existing pdb.py. the code looks like this: while True: try: pdb._runscript(mainpyfile) if pdb._user_requested_quit: break print "The program finished and will be restarted" except: traceback.print_exc() print "Uncaught exception. Entering post mortem debugging" print "Running 'cont' or 'step' will restart the program" t = sys.exc_info()[2] pdb.interaction(None, t) print "Post mortem debugger finished. The "+mainpyfile+" will be restarted" it looks like you could replace `pdb._runscript(mainpyfile)' with something like runpy.run_module(sys.argv[0], run_name="__main__", alter_sys=True) (from PEP 338). not a complete solutio

Categories : Python

Conversion of shell script to python script
It looks like you're after a templating engine, but if you wanted a straight forward, no thrills, built into the standard library, here's an example using string.Template: from string import Template with open('a.html') as fin: template = Template(fin.read()) print template.substitute(name='Bob') # <head>Bob</head> I thoroughly recommend you read the docs especially regarding escaping identifier names and using safe_substitute and such...

Categories : Python

How to return a value from a shell script in a python script
use Subprocess.check_output instead of Subprocess.call. Subprocess.call returns return code of that script. Subprocess.check_output returns byte stream of script output. Subprocess.check_output on python 3.3 doc site

Categories : Python

How to get a python script to listen for inputs from another script
I would use a socket connection. Essentially you are writing a very simple server that only takes one connection at a time import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 9988)) s.listen(1) while True: conn, addr = s.accept() data = conn.recv(1024) conn.close() my_function_that_handles_data(data) s.accept() is a blocking call. It waits for a connection. Then you do a read on the connection. In this case we are assuming the length of the parameters are only 1024 bytes. Then we do something with the data we received from the socket and wait for another connection. The client could look like this: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("localhost", 9988)) s.sendall('My parameters that I wan

Categories : Python

Bash script to wait for gnome-terminal to finish before continuing script, only works for first instance of script
#!/bin/bash date bash -c "sleep 7" & bash -c "sleep 5" & wait date As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running. Sat. Jule 27 01:11:49 2013 Sat. Jule 27 01:11:56 2013 Replace sleep 7 with expect launchneuron.exp and sleep 5 with expect launchmpj.exp and add your plot commands after calling "wait": echo "Simulation Complete" ...(your code to plot results)

Categories : Bash

PowerShell - script 1 calls script 2 - how to return value from script 2 to script 1
You could make use of ProcessStartInfo and Process which would allow you to read the StandardOutput. Here's an example of what you might do: $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = "powershell.exe" $startInfo.Arguments = "C:scriptscript2.ps1" $startInfo.RedirectStandardOutput = $true $startInfo.UseShellExecute = $false $startInfo.CreateNoWindow = $false $startInfo.Username = "DOMAINUsername" $startInfo.Password = $password $process = New-Object System.Diagnostics.Process $process.StartInfo = $startInfo $process.Start() | Out-Null $standardOut = $process.StandardOutput.ReadToEnd() $process.WaitForExit() # $standardOut should contain the results of "C:scriptscript2.ps1" $standardOut

Categories : Powershell

Powershell start-process script calls a second script - how to make one script only
Windows does not allow a process to elevate while running. There are some tricks but in one way or another they will spawn a new process with the elevated rights. See here for more info. So the easiest way for PowerShell is still using one script to Start-Process the other script elevated.

Categories : Powershell

Google Apps Script Spreadsheets - Assign script to image from a script
This would be a cool feature, but here is a possible workaround, it might even offer more functionality. You can build a UI using Google API. More detailes here. The UI allows you to create side bars/menus/etc. You could even create floating dialog windows. Using AbsolutePanel, you can even choose where the dialogue shows up.

Categories : Google Apps Script

unable to access variable declared in ksh script to csh script using shell script
The ksh script is not doing what you think it is doing when used by ksh; it sets $1 first to MyUser=root and then MyPassword=shroot. However, when you source it from your C shell script, because the syntax is compatible with C shell (checked with tcsh), you would set the two variables. If you sourced the script from a Bourne-shell derivative, the exit at the end of the ksh script would cause the shell to exit; it does not seem to cause the C shell to exit. So, what you've got is a weird hybrid. Normally, you stick to one language and use it exclusively. Where you need to use another shell, you can do so, but you simply run the script written for the other shell. You can communicate to the other script with environment variables. You don't normally try writing sourceable code that ca

Categories : Shell

Run PHP script from Java and capture the output
The output of the process can be found by using getInputStream on the returned Process from the exec call.

Categories : Java

cannot connect to Postgres (pg) database from my Ruby Script using gem "pg"(This is not rails, just pure ruby)
are you sure postgres is listening on a socket? are you sure the username and password is right? I would be inclined to try something like require 'pg' puts PG::Connection.ping(:dbname => 'oData',:user => 'am',:password => '') puts "trying with tcp" puts PG::Connection.ping(:dbname => 'oData',:user => 'am',:password => '', :port => 5432)

Categories : Ruby

calling python script from another script
you need to give it the full path to the script that you are trying to call, if you want to do this dynamically (and you're in the same directory), you can do: import os full_path = os.path.abspath('kvadrat.py')

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.