Latest recipes tagged "command"http://code.activestate.com/recipes/tags/command/new/2017-03-31T14:30:30-07:00ActiveState Code RecipesUnix tee-like functionality via a Python class (Python) 2017-03-31T14:30:30-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580767-unix-tee-like-functionality-via-a-python-class/ <p style="color: grey"> Python recipe 580767 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tee/">tee</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>The Unix tee commmand, when used in a command pipeline, allows you to capture the output of the preceding command to a file or files, while still sending it on to standard output (stdout) for further processing via other commands in a pipeline, or to print it, etc.</p> <p>This recipe shows how to implement simple tee-like functionality via a Python class. I do not aim to exactly replicate the functionality of the Unix tee, only something similar.</p> <p>More details and sample output here:</p> <p><a href="https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html</a></p> A simple text file pager in Python (Python) 2017-02-10T21:34:45-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580755-a-simple-text-file-pager-in-python/ <p style="color: grey"> Python recipe 580755 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/pagination/">pagination</a>, <a href="/recipes/tags/paging/">paging</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe shows how to create a simple text file pager in Python. It allows you to view text content a page at a time (with a user-definable number of lines per page). Like standard Unix utilities, it can either take a text file name as a command-line argument, or can read the text from its standard input, which can be redirected to come from a file, or to come from a pipe. The recipe is for Windows only, though, since it uses the msvcrt.getch() function, which is Windows-specific. However, the recipe can be modified to work on Unix by using things like tty, curses, termios, cbreak, etc.</p> <p>More details here:</p> <p><a href="https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/02/tp-simple-text-pager-in-python.html</a></p> A utility like Unix seq (command-line), in Python (Python) 2017-01-08T17:48:57-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580744-a-utility-like-unix-seq-command-line-in-python/ <p style="color: grey"> Python recipe 580744 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/seq/">seq</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This recipe shows how to create a utility like Unix seq (command-line), in Python. seq is described here: </p> <p><a href="https://en.wikipedia.org/wiki/Seq_%28Unix%29" rel="nofollow">https://en.wikipedia.org/wiki/Seq_(Unix)</a></p> <p>but briefly, it is a command-line utility that takes 1 to 3 arguments (some being optional), the start, stop and step, and prints numbers from the start value to the stop value, on standard output. So seq has many uses in bigger commands or scripts; a common category of use is to quickly generate multiple filenames or other strings that contain numbers in them, for exhaustive testing, load testing or other purposes. A similar command called jot is found on some Unix systems.</p> <p>This recipe does not try to be exactly the same in functionality as seq. It has some differences. However the core functionality of generating integer sequences is the same (but without steps other than 1 for the range).</p> <p>More details and sample output are here:</p> <p><a href="https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html</a></p> <p>The code is below.</p> Process Delimiter-Separated Values data with Python (Python) 2016-11-24T23:57:35-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580722-process-delimiter-separated-values-data-with-pytho/ <p style="color: grey"> Python recipe 580722 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dsv/">dsv</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This recipe shows how to read and process delimiter-separated values (DSV) data with a Python command-line program. It provides two ways of specifying the delimiter character, by an ASCII character or an ASCII code, which makes it more flexible than allowing only a character. It allows the DSV data to be specified as one or more filenames on the command line, or given via the standard input of the program.</p> Run OS command with timeout on a list of files using several threads (Python) 2015-05-19T19:31:59-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579056-run-os-command-with-timeout-on-a-list-of-files-usi/ <p style="color: grey"> Python recipe 579056 by <a href="/recipes/users/4182514/">Antoni Gual</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/threading/">threading</a>). Revision 3. </p> <p>This hack runs a command sequentially on a list of files using two simultaneous threads. If one of the commands takes more than a set time, it's killed and the program goes for the next file. EDITED to add some exception handling.</p> Run some command every x seconds (Python) 2013-09-24T13:26:19-07:00Rutger Saalminkhttp://code.activestate.com/recipes/users/4187940/http://code.activestate.com/recipes/578673-run-some-command-every-x-seconds/ <p style="color: grey"> Python recipe 578673 by <a href="/recipes/users/4187940/">Rutger Saalmink</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/iterative/">iterative</a>, <a href="/recipes/tags/os/">os</a>, <a href="/recipes/tags/run/">run</a>). </p> <p>Sometimes it comes in handy to run some command every minute or hour. For example, have some process check your ip address every minute with 'ifconfig' or run some purgescript at midnight through 'sqlplus.exe @purge_aux_table'.</p> Execute remote commands on windows like psexec (Python) 2011-11-18T11:54:42-08:00Ofer Helmanhttp://code.activestate.com/recipes/users/4179914/http://code.activestate.com/recipes/577945-execute-remote-commands-on-windows-like-psexec/ <p style="color: grey"> Python recipe 577945 by <a href="/recipes/users/4179914/">Ofer Helman</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/windows/">windows</a>). Revision 4. </p> <p>This code attempts to implement psexec in python code, using wmi. As part of a project of mine I had to run remote commands on remote Windows machines from other Windows machine. At first I used psexec for that with subprocess.Popen. The reason in this code for creating .bat files and running them remotely is because complicated commands do not run properly with Win32_Process.Create</p> <p>In this code I used this code: <a href="http://code.activestate.com/recipes/442521/history/3/" rel="nofollow">http://code.activestate.com/recipes/442521/history/3/</a></p> <p>required installations:</p> <p>pywin32 - <a href="http://sourceforge.net/projects/pywin32/files/pywin32/Build216/" rel="nofollow">http://sourceforge.net/projects/pywin32/files/pywin32/Build216/</a></p> <p>wmi - <a href="http://timgolden.me.uk/python/downloads/" rel="nofollow">http://timgolden.me.uk/python/downloads/</a></p> Bash completed man and info pages generation (Python) 2011-08-24T03:14:13-07:00Josh Dhttp://code.activestate.com/recipes/users/4179060/http://code.activestate.com/recipes/577854-bash-completed-man-and-info-pages-generation/ <p style="color: grey"> Python recipe 577854 by <a href="/recipes/users/4179060/">Josh D</a> (<a href="/recipes/tags/a/">a</a>, <a href="/recipes/tags/all/">all</a>, <a href="/recipes/tags/and/">and</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/be/">be</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/completed/">completed</a>, <a href="/recipes/tags/consume/">consume</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/first/">first</a>, <a href="/recipes/tags/generation/">generation</a>, <a href="/recipes/tags/get/">get</a>, <a href="/recipes/tags/in/">in</a>, <a href="/recipes/tags/info/">info</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/man/">man</a>, <a href="/recipes/tags/modify/">modify</a>, <a href="/recipes/tags/must/">must</a>, <a href="/recipes/tags/only/">only</a>, <a href="/recipes/tags/pages/">pages</a>, <a href="/recipes/tags/possibilties/">possibilties</a>, <a href="/recipes/tags/possiblities/">possiblities</a>, <a href="/recipes/tags/py/">py</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/run/">run</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/so/">so</a>, <a href="/recipes/tags/tab/">tab</a>, <a href="/recipes/tags/terminal/">terminal</a>, <a href="/recipes/tags/the/">the</a>, <a href="/recipes/tags/this/">this</a>, <a href="/recipes/tags/to/">to</a>). Revision 6. </p> <p>The script it self is very self explaining - the task is simple. *NIX only unless with cygwin perhaps?</p> <p>To start this open a terminal and strike the "Tab" key to get all possibilities (strike y, and strike the space key alot). Select all then Copy and save in "comms.txt" Modify the file so ONLY the possiblities consume a line; no prompts or extra newlines. (first line must be a command, the last line must be a command)</p> <p>Save the file ("~/Documents/bashing/comms.txt" is my path) then run this script in "~/Documents/bashing/".</p> <p>This generates two (2) files: "bash_help_man.sh", "bash_help_info.sh".</p> <p>Then it runs these files: "bash bash_help_man.sh", "bash bash_help_info.sh".</p> <p>This produces 2 files for every command (every line) in "comms.txt". All manpages are wrote in "mans/", all infopages are wrote in "infos/"</p> <p>There is now alot of files to read and organize; lets separate these by size. Directories are under1kb, under2kb, etc.</p> <p>Once complete do as you wish the files less than 128 kb; these files are COPIED into there new respective home, I repeat COPIED.</p> <p>The files 128 kb and higher ARE NOT copied to anywhere!</p> Simple Regular Expression Tester (Python) 2010-12-25T00:12:44-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577517-simple-regular-expression-tester/ <p style="color: grey"> Python recipe 577517 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/quick/">quick</a>, <a href="/recipes/tags/re/">re</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/testing/">testing</a>). Revision 2. </p> <p><strong><em>Is it possible to create a simple command line program that I can use to quickly test my regular expressions?</em></strong></p> <p>Yes it is. This simple regular expression tester uses Python's re module as well as others to quickly allow you to test your regular expression in one go.</p> <p>TODO:</p> <ul> <li>Add Support For Multiple Regular Expression Input</li> </ul> <p>Recent Changes:</p> <ul> <li>Made the output prettier with a little more whitespace. More bytes, but at least it's easier to read!</li> </ul> Better quote module for bash shells (Python) 2010-12-03T09:16:45-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577483-better-quote-module-for-bash-shells/ <p style="color: grey"> Python recipe 577483 by <a href="/recipes/users/4173535/">Kevin L. Sitze</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/escape/">escape</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/quote/">quote</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>This Python module quotes a Python string so that it will be treated as a single argument to commands ran via os.system() (assuming bash is the underlying shell). In other words, this module makes arbitrary strings "command line safe" (for bash command lines anyway, YMMV if you're using Windows or one of the (less fine) posix shells).</p> A Buttonbar program with color (Python) 2010-11-16T07:02:50-08:00Phil Risthttp://code.activestate.com/recipes/users/4171119/http://code.activestate.com/recipes/577462-a-buttonbar-program-with-color/ <p style="color: grey"> Python recipe 577462 by <a href="/recipes/users/4171119/">Phil Rist</a> (<a href="/recipes/tags/buttonbar/">buttonbar</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/execution/">execution</a>, <a href="/recipes/tags/win32/">win32</a>). Revision 2. </p> <p>An improved buttonbar program. Allows user to execute command by clicking button. <br /> Designed to be executed from a file association on a Win32 platform. Replaces <a href="http://code.activestate.com/recipes/577038/">recipe 577038</a>. Useful for commands requiring multiple related files.</p> Extract, expand and execute command from file (Python) 2010-11-05T22:24:40-07:00Phil Risthttp://code.activestate.com/recipes/users/4171119/http://code.activestate.com/recipes/577454-extract-expand-and-execute-command-from-file/ <p style="color: grey"> Python recipe 577454 by <a href="/recipes/users/4171119/">Phil Rist</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/expansion/">expansion</a>, <a href="/recipes/tags/macro/">macro</a>). </p> <p>This program extracts, expands and executes a command stored in an arbitrary file usually the primary file. This is similar to the #! facility in UNIX. </p> Extract, expand and execute command from QEditor menu file in file association (Python) 2010-11-05T22:01:40-07:00Phil Risthttp://code.activestate.com/recipes/users/4171119/http://code.activestate.com/recipes/577453-extract-expand-and-execute-command-from-qeditor-me/ <p style="color: grey"> Python recipe 577453 by <a href="/recipes/users/4171119/">Phil Rist</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/expansion/">expansion</a>, <a href="/recipes/tags/macro/">macro</a>). </p> <p>Given a path to a primary file and a menu path, a section name and a command key, extract a command from a QEditor menu and execute it. Useful from context menu entries. Example use DoM.py -m {o}\menus.ini do.py * list, on my computer searches c:\source\python\menus.ini for the first command whose key begins with list. The command is executed without capturing its standard output.</p> Simple command submitter for Win32 (Python) 2010-10-25T01:59:49-07:00Phil Risthttp://code.activestate.com/recipes/users/4171119/http://code.activestate.com/recipes/577439-simple-command-submitter-for-win32/ <p style="color: grey"> Python recipe 577439 by <a href="/recipes/users/4171119/">Phil Rist</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/expanding/">expanding</a>, <a href="/recipes/tags/win32/">win32</a>). </p> <p>This program is a simple Win32 command submitter. It uses a set of macros similar to those used by the QEditor program, strings such as '{b}'. The macros are replaced with text from a specified file path. Options to change the working directory and selected environment variables are provided. Two examples are provided in the code. <br /> The program does not collect output or provide input. It does one call to the expand routine. It can not recognize parameters containing white space. Do2 which follows does. Module is used by Do2 and ButtonBarV1Ex which follow.</p> RSH with timeout (Python) 2010-09-13T06:49:35-07:00Shrinidhi Raohttp://code.activestate.com/recipes/users/4174946/http://code.activestate.com/recipes/577390-rsh-with-timeout/ <p style="color: grey"> Python recipe 577390 by <a href="/recipes/users/4174946/">Shrinidhi Rao</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/execution/">execution</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/rsh/">rsh</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/timeout/">timeout</a>). </p> <p>RSH sometimes hangs if it cannot resolve to a given host. So here is a quick recipe in python </p> Attributes as local variables inside a with clause (Python) 2010-08-25T16:42:13-07:00Joakim Petterssonhttp://code.activestate.com/recipes/users/4174760/http://code.activestate.com/recipes/577372-attributes-as-local-variables-inside-a-with-clause/ <p style="color: grey"> Python recipe 577372 by <a href="/recipes/users/4174760/">Joakim Pettersson</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/prototyping/">prototyping</a>, <a href="/recipes/tags/syntax/">syntax</a>). Revision 2. </p> <p>This recipe defines three context managers that make it easier to step in and out of different parameter sets (‘Attributes’), allows data inheritance on such data sets (‘Scope’) and lets remote interpreters behave likewise (‘Workspace’). Just use “with object:” and there you have all its attributes ready to use as local variables. Changes are committed back into the object on exit from the ‘with’ clause. </p> TwitterCmd - Interactive console for twittering (Python) 2009-10-08T02:15:19-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/576923-twittercmd-interactive-console-for-twittering/ <p style="color: grey"> Python recipe 576923 by <a href="/recipes/users/760763/">Anand</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/microblogging/">microblogging</a>, <a href="/recipes/tags/shortcuts/">shortcuts</a>, <a href="/recipes/tags/twitter/">twitter</a>). Revision 4. </p> <p>TwitterCmd is an interactive console for twitter built on top of python-twitter library. It provides short, easy to remember commands for most twitter actions and provides a one-way interaction with the Python interpreter, exposing its objects to further inspection by the python-twitter API.</p> Send Email (Python) 2012-08-26T11:23:54-07:00sfwgeekhttp://code.activestate.com/recipes/users/4170734/http://code.activestate.com/recipes/576807-send-email/ <p style="color: grey"> Python recipe 576807 by <a href="/recipes/users/4170734/">sfwgeek</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/send/">send</a>, <a href="/recipes/tags/smtplib/">smtplib</a>). Revision 5. </p> <p>A Command Line Interface (CLI) program to send email.</p> commanding via a duplex pipe stream. (C) 2009-06-07T01:41:19-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576773-commanding-via-a-duplex-pipe-stream/ <p style="color: grey"> C recipe 576773 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/pipe/">pipe</a>). Revision 2. </p> <p>commanding via a duplex pipe stream.</p>