w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
How to execute code when a Python script is closed out?
import MySQLdb con = MySQLdb.connect(...) cursor = con.cursor() try: # do stuff with your DB finally: con.close() The finally clause is executed on success as well as on error (exception). If you hit Ctrl-C, you get a KeyboardInterrupt exception.

Categories : Python

Execute Shell Script from python with variable
Like this ? subprocess.call(['test.sh', str(domid)]) Documentation is available on the python website

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

How can I execute a shell-script in a Bash sub-shell?
You can do the same but without eval. with-env-overrides() { ( source $HOME/.env-overrides "$@" ) } Example: $ cat ~/.env-overrides export A=1000 $ export | grep ^A= $ with-env-overrides export | ^grep A= declare -x A="1000" As you can see, in the second case, you've got an environment with the A variable.

Categories : Linux

how to get process id(pid) from forked child process in shell script
From the Bash manual: ! Expands to the process ID of the most recently executed background (asynchronous) command. i.e., use $!.

Categories : Linux

exec a php to execute shell script
Your button is not actually doing anything. The problem is that your onclick attribute should contain javascript which will run when the button is clicked, not a redirect location. Use a form with a submit button instead like this. <form action="" method="get"> <input type="submit" name="run" value="Click Me!" /> </form> I notice in your question that you are also using post data in handling the form, in which case the above will not work. You need to submit the POST data at the same time as you run the script.

Categories : PHP

shell script to process a folder path
Spaces are not allowed in variable assignation in shell, so : #!/bin/sh P='/mnt/temp/' echo "$P" Q=$(echo "$P" | sed -e "s/^.*(.)$/1/") echo "Q is $Q" echo "${P%?}" And use more quotes, see http://mywiki.wooledge.org/Quotes http://mywiki.wooledge.org/Arguments and http://wiki.bash-hackers.org/syntax/words

Categories : Shell

shell script process termination issue
SIGKILL cannot be trapped by the trap command, or by any process. It is a guarenteed kill signal, that by it's definition cannot be trapped. Thus upgrading you sh/bash will not work anyway.

Categories : Shell

how jump from staying for output of shell execute after run in an php script?
If i understand you wish to run a background process on a Windows box.Suggest try this... <?php shell_exec('start /b C:wampinphpphp5.4.3php.exe a.php'); shell_exec('start /b C:wampinphpphp5.4.3php.exe b.php'); ?>

Categories : PHP

Crontab Jobs didn't execute shell script
The cronjobs you schedule in your settings are not actually added to the crontab until you run python manage.py crontab add. RTD

Categories : Django

Why is nohup still causing a process being run in a shell script to terminate?
going to sound stupid, but change your startup command from nohup ./toplog.sh to nohup ./toplog.sh & the & makes it run as a background process further removing it from the terminal stack.

Categories : Android

How to get result from background process linux shell script?
I finally found a working solution using anonymous pipes and bash: #!/bin/bash # this executes a separate shell and opens a new pipe, where the # reading endpoint is fd 3 in our shell and the writing endpoint # stdout of the other process. Note that you don't need the # background operator (&) as exec starts a completely independent process. exec 3< <(./a.sh 2&1) # ... do other stuff # write the contents of the pipe to a variable. If the other process # hasn't already terminated, cat will block. output=$(cat <&3)

Categories : Linux

apktool command in shell script does not execute from Java program
Well, in my experience, I would say that Java is not very fond of being ran by means of script. I did a quick google search. Try the ProcessBuilder, it looks perfect for this situation, in my opinion. I hope this helps you! :)

Categories : Java

Execute shell script in gruntfile and assign result to variable
Although I'm still unclear on why the method above is not working, and welcome any feedback, after a bit of research, I found shelljs, which I was able to use to solve my problem. Since shelljs can exec shell commands synchronously, I don't have to work with callbacks when I really want things to block: module.exports = (grunt) -> shell = require 'shelljs' envvar = shell.exec('./bin/get_envvar.sh', {'silent':true}).output grunt.initConfig pkg: grunt.file.readJSON('package.json') env: dev: ENV_VAR: envvar simplemocha: options: timeout: 30000 reporter: 'spec' compilers: 'coffee:coffee-script' all: src: ['Tests/**/*.coffee'] grunt.registerTask 'test', ['env', 'simplemocha'] A lot cleaner, too! References:

Categories : Node Js

How to execute a script at the end of and Magento Order process?
You can use event/observer method of magento to do something after order is placed. you can use this event sales_order_place_after Just create one module to listen magento observer/event. In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml: <config> ... <frontend> ... <events> <sales_order_place_after> <observers> <unique_event_name> <class>{{modulename}}/observer</class> <method>your function name</method> </unique_event_name> </observers> </sales_order_place_after> </

Categories : Magento

unable to run commands in shell script after su mqm command,but able to run in putty?Pleae let me know how to execute.?
putty is interactive command line. Try the below. bash variables can be used. #!/bin/bash su - mqm -c "echo 'DISPLAY QLOCAL (<QUEUENAME>) CURDEPTH'|runmqsc QUEUEMANAGER"

Categories : Bash

Don't want php script to execute the shell command as apache user when it is executed through browser?
Sudo normally requires an interactive shell to enter your password. That's obviously not going to happen in a PHP script. If you're sure you know what you're doing and you've got your security issues covered, try allowing the Apache user to run sudo without a password, but only for certain commands. For example, adding the following line in your sudoers file will allow Apache to run sudo without a password, only for the gzip command. nobody ALL=NOPASSWD: gzip Adjust the path and add any arguments to suit your needs. Caution: There might still be complications due to the way PHP calls shell commands. Remember that it's very risky to allow the web server to run commands as root! Another alternative: Write a shell script with the suid bit to make it run as root no matter who calls i

Categories : PHP

How to write and execute a shell script to create a mysql databse and a table
Update During my next session, I realized mysql wasn't recognized by terminal. I realized i'm dumb and was just always doing things wrong. Do not use alias to resolve to a binary folder. Example, do not use alias mysql="/Applications/MAMP/Library/bin/mysql" Instead export PATH=$PATH:/Applications/MAMP/Library/bin/ This will allow you to use the binaries appropriately via bash, and you'll also gain access to all mysql binaries including mysqladmin etc from the terminal as well. :) Happy scripting! Example script with appropriate environment variables: #!/bin/bash echo "" echo Reloading Database echo "" echo Using echo PROJECT_BUILD_HOME: $PROJECT_BUILD_HOME echo MYSQL: $(which mysql) echo PHP: $(which php) echo "" echo "" mysqladmin -u root -pmypass drop projectbuild mysqladmin -u

Categories : Mysql

In a Linux script, is it possible to execute multiple commands in the same process?
If you want both instructions to run in the same process you need to write them to a script: $ cat foo.db2 connect to user01 describe indexes for table table_desc and run that script in the db2 interpreter: db2 -f foo.db2 A Here Document might work as well: db2 <<EOF connect to user01 describe indexes for table table_desc EOF I can't test that, though, since I currently don't have a DB2 on Linux at hand.

Categories : Bash

Porting windows batch file to shell script. If possible execute the task in parallel
I have to admit, I am not sure I fully understand your scenario, but to run tasks in parallel in linux, you can put them in the backgrund using &. Example: start "Engine 1500" ant start & start "Engine 1505" ant start & To call your other script, simply execute it from your first shell script. So in total you would have: clean.sh: #!/bin/sh ant -DCorrelator clean start_parallel.sh #!/bin/sh clean.sh start "Engine 1500" ant -Dengine.port="15800" -Dfamily.one="true" -Dfamily.two="false" start & start "Engine 1505" ant -Dengine.port="15800" -Dfamily.one="false" -Dfamily.two="true" start & Make sure you make both scripts executable using chmod: chmod +x clean.sh chmod +x start_parallel.sh And Linux only looks in your path (echo $PATH) for executable scripts.

Categories : Linux

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

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

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

Why does this work in the Python IDLE shell but not when I run it as a Python script from the command prompt?
As @Sukrit Kalra says, don't use datetime.py as your file name. Python is getting confused with which datetime is which (and is importing itself!). Maybe; $ mv datetime.py my_datetime.py

Categories : Python

Execute process from the windows command line in Python
By trying your code it prints out PreprocessedTufts8199PLAIN.txt.xml file name. I'm not sure if the .txt.xml extension was the desired result. If your file has only .xml extension, then you're not stripping away the original .txt header. Try to change this line: outFile = file(inFile[(str(inFile).rfind('\'))+1:] + '.xml') Into this code: fnameext = inFile[(str(inFile).rfind('\'))+1:] fname,fext = os.path.splitext(fnameext) xmlfname = fname + '.xml' xmlfpath = os.path.join(".", xmlfname) print "xmlfname:", xmlfname, " xmlfpath:", xmlfpath print "current working directory:", os.getcwd() outFile = open(xmlfpath, "r") Answer for extension stripping.

Categories : Python

Python script to run shell command
Why are you using subprocess? A common practice to run Scrapy from a script is to use twisted's reactor. Taken from docs: from twisted.internet import reactor from scrapy.crawler import Crawler from scrapy.settings import Settings from scrapy import log from testspiders.spiders.followall import FollowAllSpider spider = FollowAllSpider(domain='scrapinghub.com') crawler = Crawler(Settings()) crawler.configure() crawler.crawl(spider) crawler.start() log.start() reactor.run() # the script will block here There is plenty of examples out there: Running scrapy from script (beginner) How to run Scrapy from within a Python script Running Scrapy from a script - Hangs Scrapy crawl from script always blocks script execution after scraping Hope that helps.

Categories : Python

The script which runs python in shell
It's not a python script you can simply get and modify as any .py file. In order to play around with interactive interpretter you will have to download the python sources and go through them, as it's a build-in part of it (for performance sake). You can read up the details on http://docs.python.org/devguide/

Categories : Python

use python script in shell (like fabric)
You can make your script start with the line: #!/usr/bin/env python Or, depending on your version: #!/usr/bin/env python3.3 Then you must make your script executable with a chmod, and it should work like you want!

Categories : Python

Script doesn't want to run from python shell
Use execfile: >>>execfile('clean_index.py') or just run it directly (not within the python shell): $ python clean_index.py assuming you have python in your path. Or, use an import in the python shell: >>>import fibo >>>fibo.fib(1000) 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 Module import sample taken from the docs. The filename is fibo.py. Since you probably simply want to run the file, I suggest you use the second option.

Categories : Python

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

Can't execute python script from php
Your problem is this: When launching the php script through the console, you are launching php with the permissions of your current user. When a process is executed through opening it in the browser, it will have the permissions of the user of your web-server-process. Your group permissions will have to be 7 no matter what. Either change the python scripts permissions to 777 (read-write-execute for everybody) or change it to 770 and make sure that your web-servers user is inside the group set to the file.

Categories : PHP

submit each line to a python script using shell.
This is a shell scripting question more than it is a python one. However, I think your issue is " > test.txt" the ">" will start from a blank file each time instead of appending the results. try " >> test.txt"

Categories : Python

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

shell start / stop for python script
It is because ps aux |grep SOMETHING also finds the grep SOMETHING process, because SOMETHING matches. After the execution the grep is finished, so it cannot find it. Add a line: ps aux | grep -v grep | grep YOURSCRIPT Where -v means exclude. More in man grep.

Categories : Python

How to run a python script from IDLE interactive shell?
The IDLE shell window is not the same as a terminal shell (e.g. running sh or bash). Rather, it is just like being in the Python interactive interpreter (python -i). The easiest way to run a script in IDLE is to use the Open command from the File menu (this may vary a bit depending on which platform you are running) to load your script file into an IDLE editor window and then use the Run -> Run Module command (shortcut F5).

Categories : Python

Execute python script in localhost
Google App Engine SDK for Python includes a local web server application that simulates the App Engine environment. It allows for instant server script changes by just saving the file and refreshing the browser. The development tutorial is here Once you have your web site working locally, it is easy to deploy it live on Google's App Engine servers.

Categories : Python

Execute python in a php script using shell_exec()
I think kernel not able to find the path for python where it is installed..if you can do echo $PATH..it will show all the paths where to be search a command if given add your python part there and then it may work or you can give absolute path(other than /usr/bin/) see if it works..I need to test it too.

Categories : PHP

Execute python script using urllib2 from PHP behind Proxy
You could try passing explicit proxy settings to your Python script to see if that clears up the problem for you. I recently wrote a script that allows you to set proxy settings with command line arguments that might be useful for this case. The important parts of the script are below: # Import the required libraries from urllib import urlencode from urllib2 import Request, urlopen, URLError, ProxyHandler, build_opener, install_opener import argparse # Set up our argument parser parser = argparse.ArgumentParser(description='Does stuff through a proxy') parser.add_argument('webAddr', type=str, help='Web address of target server') parser.add_argument('--proxServ', metavar='SERV', type=str, help='Web address of proxy server, i.e. http://proxy.server.com:80') parser.add_argument('--proxType'

Categories : PHP

crontab doesn't execute my python script
First, you have an odd indentation in the line with if __name__ ==... - guess you should check it in your script. Then, make sure with what current directory your script runs, AFAIK it is your $HOME - this is where the file would appear.

Categories : Python

Execute R script with python subprocess.call
Using commandArgs like this: args <- commandArgs(trailingOnly = TRUE) arg1 <- args[1] arg2 <- args[2] [...your code...] Also make sure that the Rscript executable is in your PATH.

Categories : Python



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