w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
osx: launching a shell script containing gnu coreutils commands, works via terminal, not via applescript
Set $PATH in the shell script to include the path to the utilities: #!/bin/bash PATH=/opt/local/bin:/opt/local/sbin:$PATH path_to_open=$(...) && open "${path_to_open}"

Categories : Osx

Python code works okay via terminal, but not via wsgi script. ( TypeError: 'NoneType' object is not iterable )
WSGI requires that you return the output you want to send back to a browser as the return value of your function, not just print it out. So you'd need to use pprint.pformat() and return its result, rather than pprint.pprint (which just tries to print it out via print - not what you want here). def application(environ, start_response): start_response('200 OK', [('content-type', 'text/html')]) aaa = ['a','b','c'] return pprint.pformat(aaa)

Categories : Python

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

Python Tkinter Crashing, every run but program continues? Final polishing of Tkinter
You need RotateNO to be a part of your class. Also zoom doesn't need to take a zoom argument because you've already initialized self.Flag_Zoom. Also change root.destroy() to Exe.destroy(). Try this: # ---------- Imports ------------------------------------- # from Tkinter import * import matplotlib import numpy as np # ---------- Settings ------------------------------------ # matplotlib.use('TkAgg') import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg # ---------- Classes ------------------------------------ # class App(Frame): def __init__(self,master=None): Frame.__init__(self, master) self._job = None self.canvas = None self.Flag_Zoom = False self.pack() self._GU

Categories : Python

Running a linux command from Django views. Works fine in python shell. Won't execute from views
You should look at the error log in order to make a proper diagnostic. Without more information, I can think of two reasons: The Apache mod_wsgi restricts access to stdout, and the command you are running outputs to stdout. If you are using mod_wsgi, look for errors like IOError: sys.stdout access restricted by mod_wsgi in the logs; You are testing your command while logged in as your user or root, but the webserver is running as other user with less privileges (like www-data in Ubuntu). Find out under what user the webserver is running, su to the same user and try the same commands. Any error will hint you about the permissions lacking. It is almost always a bad idea to run a shell from a Django view, specially if the command take a few seconds to run. It has bad scalability, makes e

Categories : Python

Emacs shell has different behavior from Terminal with GCC
M-x shell starts a new shell. For me, it's a bash shell, but it could be csh or zsh or some other shell. When emacs launches a new shell, it runs ~/.emacs_SHELL where SHELL is bash or csh or something. So you can copy your shell startup file to that file and it should hopefully get your path and other environment variables set up correctly. In my case, I'm a bash user, so I copied by .profile to .emacs_bash and it worked. You might have a .bash_profile or .bashrc instead of a .profile. But the general idea is the same: put emacs shell startup commands in a .bash_WHATEVER file.

Categories : C++

Opening terminal with multiple tabs using shell script
You should always (always!) use an array for building up argument lists in bash. That is: #!/bin/bash # ^^ this has to be bash, not /bin/sh, for arrays to work cmd=( gnome-terminal ) for ((i=0; i<5; i++)); do cmd+=( --tab-with-profile=Default -e "java RunRTSPClient" ) done "${cmd[@]}" This will give you the exact equivalent of running: gnome-terminal --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" --tab-with-profile=Default -e "java RunRTSPClient" ...which is what I understand that you want. Trying to build a complex command in a string causes Very Bad Things to happen; read http://mywiki.wooledge.org/Bash

Categories : Linux

'rvm' is currently not installed. (Works on one terminal but not the other)
If you just finished to install it, to have access in all terminals you need to logout and login again, in order to load the new environmental variables on your .bashrc or .bashprofile

Categories : Ruby On Rails

Adding a shell script to be executed with the 'mrt/meteor create' command in terminal
Great question Johann! Alright, so to turn a shell script into something as convenient as a terminal command, all you need to do is create an alias for that script in your terminal's rc file. Further instructions as to how you can do that can be found here. So all you need to do is list out the commands you want automated in the shell script, including the meteor/mrt commands, and pass the directory/project name with the special variable "$1" passes the first argument after your command into your script. Here's the script I am currently using, which implements the folder structure from Discover Meteor and adds coffeescript and stylus-mixins There are probably some redundancies in commands. Let me know if you see anything that can be cleaned!

Categories : Shell

Emacs shell or terminal escape characters in compilation buffer for rails tests
Backing the comment by Alex Vorobiev, which delivered the answer. Seems you've put a comint-mode aside and with that the ansi-color-process-output filter. AFAIU fontifying is done on a per-buffer-base, run from an idle-timer resp. triggered by buffer-changes. If enabled in a output-shell, Emacs might hang, as a lot of changes may occur in short time. Therefor fontification is commonly off here. An alternative approach: M-x MY-MODE at the shell-buffer. Which might need some reset to shell environment or re-start then.

Categories : Ruby On Rails

NFC tag reading in python on raspberry pi
There are lots of links on google wherein you can find information on data format used in NFC. Some of them are http://learn.adafruit.com/adafruit-pn532-rfid-nfc/ndef http://developer.nokia.com/Community/Wiki/Understanding_NFC_Data_Exchange_Format_(NDEF)_messages

Categories : Python

sed not working from java program, but the input line works from terminal
Does the Java program perhaps run with a different environment, perhaps one where sed is not in the path? Otherwise perhaps it runs as a user who does not have write permission to the network scripts?

Categories : Java

Variables scope in inline django shell, vs python shell
It seems to be a known issue and fixed in Django 1.6. For the time being, there is a suggested workaround in the ticket. "Grab the following lines (from here https://github.com/django/django/blob/master/django/core/management/commands/shell.py) and replace the current implementation (...) with this": def ipython(self): try: from IPython.frontend.terminal.ipapp import TerminalIPythonApp app = TerminalIPythonApp.instance() app.initialize(argv=[]) app.start() except ImportError: # IPython < 0.11 # Explicitly pass an empty list as arguments, because otherwise # IPython would use sys.argv from this script. try: from IPython.Shell import IPShell shell = IPShell(argv=[]) shell.mainloop

Categories : Python

Raspberry Pi Python PWM RuntimeError: No access to /dev/mem
The problem is with the code above is that I forgot to set RED to at output before trying to use it. The error message did not help resolve this problem. Next time, I need to remember to setup PWM pins as outputs before trying to use them.

Categories : Python

Fatal error: Class 'ZMQContext' not found ( but it is installed and works on the terminal )
The problem is that the ZMQ module is loaded in the PHP CLI (Command Line Interface) but it's not loaded into Apache. Therefore, service.php runs smoothly from the Command Line but client.php can't use ZMQContext because Apache does not load ZMQ. There are two different .ini-files. These probably are (but can be different, depending on your distro): /etc/php5/apache2/php.ini for Apache /etc/php5/cli/php.ini for CLI However, all .ini files from the /etc/php5/conf.d/ directory are loaded into both Apache and the CLI. See also: PHP - An external Class/library is accessible from apache but not from phpunit (the exact opposite of your problem)

Categories : PHP

Cutting down a very large table into something importable
Is this a one-time import into Access, or do you need to do this multiple times? If it is a one time thing, I'd use a DBF filtering tool, then export it: DBF Tools DBF Viewer 2000

Categories : Database

Raspberry PI: PHP call python script with sudo
Mm, i have try with this two simple example: /Scripts/test.py #!/usr/bin/env python print (str('hello world')) /var/www/test.php <?php echo shell_exec('/Scripts/test.py'); ?> via a browser, show me "hello world" Perhaps try this: chmod a+x your_py_file.py Hope that help..

Categories : Nginx

Using Python smbus on a Raspberry Pi - confused with syntax
I'm absolutly not sure this is the problem, but according to the specs p22: MMA7660FC is read using it’s internally stored register address as address pointer, the same way the stored register address is used as address pointer for a write. The pointer generally auto-increments after each data byte is read using the same rules as for a write (Table 5). Thus, a read is initiated by first configuring the device’s register address by performing a write (Figure 11) followed by a repeated start. The master can now read 'n' consecutive bytes from it, with the first data byte being read from the register addressed by the initialized register address. As far as I understand, to "read" from a register, you have to start by writing the register address, and then blindly read a byte

Categories : Python

Creating project file through terminal and compile failes but through Qt Creator IDE works fine
This is the bug in Qt, When creating project file from the Terminal using command qmake -project, the generated project file does not contain line: greaterThan(QT_MAJOR_VERSION, 4): QT += widgets. That may be the reason why qmake doesn’t include “-I/opt/Qt5.1.0/5.1.0/gcc/include/QtWidgets” in your MAKEFILE. More info QT BUG.

Categories : C++

Running Python script causes Raspberry Pi to lose power
I tried your script. It locks up the rpi at this line GPIO.setup(6,GPIO.IN,pull_up_down=GPIO.PUD_DOWN) GPIO06 isn't one of the pins on the GPIO port. You'd have look at the schematic to see what it's connected to. Looks like it's LAN_RUN. What are you trying to do with it? From elinux.org GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function. So unless you have a model A, you shouldn't be using GPIO06

Categories : Python

No video file created by OpenCV 2.3.1 with Python on Raspberry Pi
I eventually went through and tried all of the fourcc codecs and none worked. Same with the mpeg2 codec. I ended up using avconv to create and capture the video with this line: import os os.system("avconv -f video4linux2 -input_format mjpeg -i /dev/video0 output.avi") os.system() is used to run a terminal command. OpenCV can still be used to process the video files at a later time. Hope this helps someone.

Categories : Opencv

Raspberry pi will not send serial data to an arduino using either minicom or python
You need to read up on the difference between arduino and raspPI 'serial' pins - in short, their voltage levels are quite different and require a conversion cable between the two of them to adjust these levels.

Categories : Python

Twisted Python script on Raspberry Pi (Debian) to communicate with Arduino via USB
Judging from this: http://twistedmatrix.com/trac/browser/tags/releases/twisted-12.3.0/twisted/internet/_win32serialport.py#L84 you should be looking at dataReceived(self,...) method of your Protocol subclass Thus: class USBclient(Protocol): def connectionMade(self): global serServ serServ = self print 'Arduino device: ', serServ, ' is connected.' def cmdReceived(self, cmd): serServ.transport.write(cmd) print cmd, ' - sent to Arduino.' pass def dataReceived(self,data): print 'USBclient.dataReceived called with:' print str(data) try this to see if it works.

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 to export the result set of a postgres query in a format that is importable with psql?
Have a look at the --inserts option of pg_dump pg_dump -t your_table --inserts -f somefile.txt your_db Edit the resulting file if necessary. For a subset, as IgorRomanchenko mentioned, you can use COPY with a SELECT statement. Example of COPYing as CSV. COPY (select * from table where foo='bar') TO '/path/to/file.csv' CSV HEADER

Categories : Postgresql

How can I make a connection between Raspberry Pi and a Bluegiga WT11i Bluetooth Module using Python?
Got it!! pi@raspberrypi ~ $ aptitude install bluetooth pi@raspberrypi ~ $ hcitool dev Devices: hci0 00:07:80:54:CA:E2 pi@raspberrypi ~ $ hcitool scan Scanning ... 00:07:80:54:CA:E2 BGWT11i pi@raspberrypi ~ $ bluez-simple-agent hci0 00:07:80:54:CA:E2 Enter PIN Code: 1234 Now I can connect ... pi@raspberrypi ~ $ python rfcomm-client.py 00:07:80:54:CA:E2

Categories : Python

Python having trouble accessing usb microphone using Gstreamer to perform speech recognition with Pocketsphinx on a Raspberry Pi
So I finally got this guy working. Couple key things I needed to realize: 1. Even if you're using Pulseaudio on your Raspberry Pi, as long as Alsa is still installed you're still able to use it. ( This might seem like a no brainer to others, but I honestly didn't realize I could still use both of these at the same time ) Hint via (syb0rg). 2. When it comes to sending large amounts of raw audio data ( .wav format in my case ) to Pocketsphinx via Gstreamer, (queues) are your friend. After messing around with gst-launch-0.10 on the command line for a while I came across something that actually worked: gst-launch-0.10 alsasrc device=hw:1 ! queue ! audioconvert ! audioresample ! queue ! vader name=vader auto-threshold=true ! pocketsphinx lm=/home/pi/dev/scarlettPi/config/speech/lm/scarlett

Categories : Python

Porting Python Raspberry Pi application to Twisted - how to handle background threads that poll the hardware
You can use LoopingCall (howto) to schedule a repeated function call on a certain interval. This probably replaces your polling threads entirely.

Categories : Python

shell script fails when executed by cronjob, works fine otherwise
Your cron job doesn't have access to the same $PATH variable that you as a user have. The easiest way to fix this is to open up a terminal, and run this command: which java That's going to give you the absolute path of your java executable. For example: /opt/Oracle/Java/bin/java Replace your 'java' command with the whole path. You might also want to specify the JAVA_HOME variable in your shell script. From your terminal run: echo $JAVA_HOME That'll give you another path, like '/opt/Oracle/Java'. In your script (assuming you are using bash), before you run the java command, put: export JAVA_HOME=/opt/Oracle/Java Replacing '/opt/Oracle/Java' with the output that the previous echo gave you.

Categories : Java

Unable to bind to port 80, but running on the current shell works without any issues
you need root access to bind to lower ports like port 80. rvmsudo executes in root context and therefore it works. cap task executes in a normal user context (probably deploy) depending on your configuration. you should add sudo ability to cap deploy user and make sure your cap task uses sudo to start unicorn.

Categories : Ruby On Rails

importing celery in project fails, works(sort of) in manage.py shell
Try altering tasks.py to: from __future__ import absolute_import from celery import task It's possible that you have a celery/ or celery.py in the same directory as the module throwing the error (tasks.py), and this is failing as a relative import.

Categories : Django

Python Tkinter - Name is not defined
Using exec is almost always the wrong way to do it, no matter what "it" is. And creating variables dynamically is almost always the wrong thing to do. And your problems getting this to work are a perfect illustration of why. Just create a dict mapping names to buttons: buttons = {} # ... letter = alphabet[i] buttons[letter] = Button(frame, text = letter, command = letterAction(letter)) buttons[letter].place(x = x, y = y, width = width, height = height) If you really want to dump the dict into locals() (or, similarly, self.__dict__ or globals() or …), that's trivial. But you don't. The only place you need to use the variable is in your letterAction function. So: def createLetters(frame, startX, startY, width, height, spacing): alphabet = string.ascii_uppercase buttons

Categories : Python

Python tkinter image
Separate encoded image data into module. Main script import images ... myimage1 = PhotoImage(data=images.image1) myimage2 = PhotoImage(data=images.image2) ... images.py image1 = 'encoded image data...' image2 = 'encoded image data...'

Categories : Python

TypeError when using tkinter (python)
You did not created match object. (missing ()) Replace following line: self.match = match with self.match = match()

Categories : Python

Python Tkinter PhotoImage
It does not matter much where you declare the image, as long as you create it after initializing Tk() (the problem in your first approach) the image is in the variable scope when you are using it (the problem in your second approach) the image object does not get garbage-collected (another common pitfall) If you define the image in your main() method, then you will have to make it global class MyCustomWindow(Tkinter.Frame): def __init__(self, parent): Tkinter.Frame.__init__(self, parent) Tkinter.Label(self, image=image).pack() self.pack(side='top') def main(): root = Tkinter.Tk() global image # make image known in global scope image = Tkinter.PhotoImage(file='image.gif') MyCustomWindow(root) root.mainloop() if __name__ == "__main__":

Categories : Python

Python Tkinter GUI scrambled
The problem is that you forgot to give your Labels a root widget. Honestly I'm surprised they showed up at all - I think they must have defaulted to the active Tk instance, so they got gridded outside the frame. Anyhow, the fix is easy - add self as the first argument of all your Labels. I.e. wherever you wrote something like this: self.t_start_label = Label(text="start time") instead write this: self.t_start_label = Label(self, text="start time") ^^^^ The Labels then appear next to the Entries. One style note - I recommend that you move all your Widget.grid calls to one place in your code - makes it much easier to read, understand, and change the grid layout.

Categories : Python

stop python in terminal on mac
CTRL+d -> Defines EOF (End of File). CTRL+c -> Will terminate most jobs. If, however you have written a python wrapper program that calls other python programs in turn, Ctrl-c will only stop the the job that is currently running. The wrapper program will keep running. Worst case scenario, you can do this: Open up: Applications -> Utilities -> Activity Monitor, Find the process labeled as python, highlight it in the activity monitor then click on "Quit Process". These three suggestions should work for most situations where you want a program to stop.

Categories : Python

python subprocess terminal mac osx
First, I doubt that command you are trying to run will run at all. Did you try it in terminal first? open -an Terminal will give you an error. It probably should be something like open -n /Applications/Utilities/Terminal.app Second, @korylprince is right: open itself will create new process of Terminal and exit. So you are linking pipe with wrong process. Third, at the moment of passing ls to the stdin that process doesn't exist already (unless you will pass -W option to the open, but it certainly will not help due to the 2 problem). So I see only one opportunity to do this: via AppleScript. You can create an AppleScript string, something like next: tell application "System Events" tell process "Terminal" keystroke "ls" keystroke return end tell end tell and t

Categories : Python

python 3.3 tkinter-- "window' is not defined'
your missing one line. You need to add window = Tk() so your code should look like: from tkinter import * window = Tk() window.title("Test Window") window.geometry('300x300') window.wm_iconbitmap('Generals.ico') # Generals.ico is a filename for the window icon lbl = tkinter.Label(window, text='Label') lbl.pack() window.mainloop() Not sure if this is 100% correct cause I'm using python 2.7. You might not need to capitalive the 'T' in tk()

Categories : Python

Python tkinter trace method
stringvar1 is garbage collected (deleted) when Entrybox_002 function return. Workaround: stringvar1 = window2.stringvar1 = tk.StringVar(value='asdf') I recommend you code Entrybox_002 as class, and stringvar1 as instance attribute to keep reference.

Categories : Python



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