EzDev.org

interactive-shell

bash script for learning basics of UNIX terminal.


Is it possible to paste code into PHP's interactive shell without a tab prompt?

Whenever I've tried to paste large blocks of code (whole classes, long code snippets, etc.), I'm always greeted by this message for each line of code inputted:

Display all 3616 possibilities? (y or n)

I'm pretty sure it's because my code is indented and it's triggering the tab functionality by pasting the tab character. If this was just a visual annoyance, I wouldn't care, but it tends to randomly stop processing lines in the middle of a method and then demands that I type y or n.


Source: (StackOverflow)

\n displaying in interactive shell

I'm a newbie scriptwriter and I was testing out my script using the interactive shell -i.

This is part of my script:

shelp = "min               shows the number of minutes\n\
sec               shows the number of seconds\n\
min + [NUMBER]    adds the number of minutes\n\
sec + [NUMBER]    adds the number of seconds"

When I run shelp in interactive, it shows:

'min               shows the number of minutes\nsec               shows the number of seconds\nmin + [NUMBER]    adds the number of minutes\nsec + [NUMBER]    adds the number of seconds'

I'm not sure if this is what it is supposed to do but is there a way to remove the \n while still be able to run my script in interactive?

Sorry if this is had already been answered or if I got my facts wrong


Source: (StackOverflow)

Is it possible to redirect Boris output (PHP interactive command line)?

I am using Boris—"A tiny little, but robust REPL for PHP". To be more specific, I am using WP-CLI's implementation of Boris (wp shell—it replaces the $boris command prompt with wp>).

I was wondering if it was possible to pipe the command line output to say, a text file. For example, I want to capture my PHP info to a text file. Here is what happens when I execute phpinfo();

wp> phpinfo();

    phpinfo()
    PHP Version => 5.3.14

    System => Darwin Macintosh-HD.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May  1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64
    Build Date => Jul  4 2012 17:23:04
    Configure Command =>  './configure'  '--with-mysql=/...

    //phpinfo() output continues here

I want to redirect this output from the standard display to a text file. I know this is bash syntax, but this is what I want to achieve in theory :

wp> phpinfo(); > phpinfo.txt

    // phpinfo.txt now contains phpinfo() output

Is there any way to make this work?


Source: (StackOverflow)

How to run manage.py in Eclipse Pydev Interactive Console

I am trying to run manage.py to validate models (as: manage.py validate) in the Interactive Shell of a Django project (called djangonew) using Pydev

The PYTHONPATH is set to include /djangonew ... so import djangonew and then dir(djangonew) actually gives me a name as 'settings' in the subfolder /djangonew/djangonew

but at the command-line I am unable run manage.py (and even find it)

How do I solve this issue? Thanks much


Source: (StackOverflow)

How to continue in nested loops (after 2nd innerloop) in BASH?

Would like kindly to ask for you advice.

I'm building interactive bash script with nested loops using while true, read and case. My problem is that after second innerloop (when choosing 'loop 1.3') I'd like to continue script with another inner loop, but it fails (part with my comment about failure).

I assume I'm missing something in syntax, but can't find it out...

Below is the code of the script. Thanks in advance.

#!/bin/bash
while true; do
read -rep $'Loop #1 (outerloop)? \n\tYES\tNO\n\n' yn
case $yn in
    [Yy]* )
    while true; do
    read -rep $'Loop #1.2 (first inner loop)? Please, choose variant 1 or 2.\n\t1\t2\n\n' yn
    case $yn in
    [1]* )
            while true; do
            read -rep $'Loop #1.3 (second inner loop)?\n\tYES\tNO\n\n' yn
            case $yn in
            [Yy]* ) read -rep $'Loop #1.3. Variant Yes.:\n\n' LOOP3Q1; break 3;;
            [Nn]* ) break 3;;
            esac
            done; break 3;;
    [2]* ) 
            while true; do
            read -rep $'Loop #1.3 (second inner loop).\n\tYES\tNO\n\n' yn
            case $yn in
            [Yy]* ) read -rep $'Loop #1.3 variant Yes.\n\n' LOOP3Q2; break 3;;
            [Nn]* ) break 3;;
            esac
            done; break 3;;
# Here it failes. If here I break all loops - it works, but I need to continue...
            echo "Continue loop 1.2 (first inner loop)"
            while true; do
            read -rep $'Loop #1.3 (second inner loop).\n\tYES\tNO\n\n' yn
            case $yn in
            [Yy]* ) read -rep $'Loop #1.3 variant Yes.\n\n' LOOP3Q2; break 3;;
            [Nn]* ) break 3;;
            esac
            done; break 3;
    esac
    done; break 2;;
    Nn]* ) break;;
 esac
 done

Source: (StackOverflow)

Bash interactive and non-interactive shell behaviour

I have a hard time with interactive and non-interactive shells. I don't understand which is which.

For example, I have read that non interactive shells usually check for the BASH_ENV variable on their startup and execute whatever it points to.

So, what I did is I set the BASH_ENV to point to some script which only echoes OK. Then I typed in bash in terminal and this script echoed OK. But why? Didn't I call yet another INTERACTIVE shell by typing bash in terminal, and not the other way around? Why did it execute the bash_env? I'm on linux mint maya.


Source: (StackOverflow)

Custom interactive terminal (CLI) with autocompletion on classes and objects

I would like to have an interactive prompt similar to IPython within a program.

The features I would like to have are:

  • Custom prompt
  • Auto-completion on object's methods and attributes
  • Execution of methods, read/write attributes
  • Display docstring on error

So far I've been playing with readline with an auto-completion callback function and magic methods such as __dir__, __doc__ or __dict__.

I am sure I can implement such solution, but I am looking for an existing module that can do the job for me.

In my idea I would like to use it like this:

class Foo:
    def Say(self): 
        return "The answer is 42"
foo = Foo()

cli = Cli() # The terminal interface I want to have
cli.RegisterObject(foo, showAttributes = True, showProtected = True)
cli.AddCommand('exit', exit)
cli.Start(defaultPrompt = ">")

A friend advised me to use IPython instead of a custom solution. Unfortunately IPython is too open for my application where newbies will get confused for sure. I don't want the final user to have access to everything.

At the end we will have something like this:

$ ./cli.py
>foo.<tab>
Say
>foo.Say()
The answer is 42
>bar.AreYouHere()
Unknown command!
>exit

Some related questions are:

Unfortunately the answers advise to use cmd module which is not very much what I need.


Source: (StackOverflow)

how to compile php with the --with-readline option

I recently asked this question about a PHP interactive shell, similar to python's. after viewing this page it looks like what I need to do is compile PHP with the --with-readline option. The problem is, on Windows, I don't know how to do that. Can anyone help me?


Source: (StackOverflow)

Developing an interactive shell

I have an application; to interact with it I have to develop an interactive shell. The shell will take input from user and dispatch it to the server, which will process and return a response.

In the past I have done such things, but they typically had the following format:

Shell>> COMMAND arg1 arg2 arg3 ..

and my implementation was in a manner similiar to:

/* Mock implementation */
while(true) {
   in = readline()
   tokens = in.split(' ') //split based on space
   switch(token[0])  {
      case "Command_a": processA(token[1], token[2])
      case "Command_b": processB(token[1], token[2], token[3])
   }
}

This time I have to work with more extensive grammar for user input. If I use my current approach, it will make things very difficult with lots of if , if-elseif-else, if-else, switch statements for both parsing and generating response.

How can I approach this problem in a manner that will make the interpreter modular and maintainable? What are some ways in which popular CLI-Interface are implemented? I will really appreciate some code examples.

PS: Language choices limited C++/Python


Source: (StackOverflow)

Start pig grunt shell and execute commands using c#

I am working on achieving the execution of commands on pig grunt shell using c#. I am able to start the grunt shell through c# program using the following code:

proc = new Process {StartInfo = new ProcessStartInfo
                    {
                        FileName = PIG_BIN + "\\pig.cmd",                
                        UseShellExecute = false,
                        RedirectStandardError = true ,
                        RedirectStandardOutput = true,
                        RedirectStandardInput = true,
                        CreateNoWindow = true
                    }
                };

I read the output and error through the following methods and events:

     proc.OutputDataReceived += proc_OutputDataReceived;
  proc.BeginOutputReadLine();
  proc.ErrorDataReceived += proc_ErrorDataReceived;
  proc.BeginErrorReadLine();

But, I am unable to read the output line from grunt shell. But, only the lines before the "grunt>" is alone read.

I pass arguments to grunt shell through the following command,

proc.StandardInput.WriteLine("dump a;");

I am not able to pass the arguments to grunt shell too. A java process is started when we start the grunt shell. If I end the java.exe in command prompt, "OutputDataReceived " event is hit and "grunt>" is obtained.

I hope that grunt is running as a java process and hence we are not able to pass and receive arguments to and from it. Is there any way to achieve it??


Source: (StackOverflow)

How to avoid global vars (/abuse of builtin): Sharing data between modules/classes (Python3)

I wish to have an interactive shell that allows me to perform data manipulation using a series of modules defined in my package. For example, I want to be able to type:

$ Input('data.csv')
$ GroupBy('key')
$ Output('data.csv')

Where Input, GroupBy and Output are all modules/classes of my package that implicitly operate on some 'global' data iterator. The easy way to do this would be to explicitly pass data as an argument, but I want the control over what happens to data to be in the background (maybe I'm distributing it across compute cores and map-reducing, without the user knowing).

This is the closest I've got so far:

class env(object):
    def __init__(self):
            self.data = []
            code.interact(local=locals())

    def __iter__(self):
            return self.data

    def run(self, className, *args, **kwargs):
            c = globals()[className](*args, **kwargs)
            self.data = chain(self.data, c)

    def __getattr__(self, attrName, *args, **kwargs):
            return partial(self.run, attrName)

Then within my package __init__.py I instigate env. My env.py will then import the rest of the package modules into it's own namespace (for example Input, GroupBy and Output), which let's me do:

$ self.Input('data.csv')
$ self.GroupBy('key')
$ self.Output('data.csv')

So close, but I want to get rid of the self!

I thought what I could do was make my env class inherit from dict, and then do code.interact(local=self), but sadly this does not seem to work?

Please tell me how to achieve this in a Pythonic way (or explain why what I'm trying to do is not Pythonic and offer an alternative), otherwise I'm going to be very naughty and add data to builtins so I can access it globally across modules...

tl,dr; How do I wrap all of my package's modules within a class that controls access to global data?


Source: (StackOverflow)

How to get sentiment via stanford corenlp interactive shell?

Interactive shell with all annotators including sentimentI have been trying to get the sentiment value from the stanford corenlp, but it seems in the interactive shell, the sentiment is not given as an output.

I have specified the annotators using the command given in the official website.

java -cp "*" -Xmx3g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref, sentiment

Also, when i tried for getting just the sentiment, then at first asked for other annotators, after providing i didn't give any output at all.

I am getting the interactive shell in both the cases. Like - NLP> But, there is no sign of sentiment - positive or negative.

Also, if we use the sentimentPipeline instead of nlp.pipeline. It gives the sentiment. Is there any way i can get via the interactive shell or if possible is there any way we can use sentimentPipeline with pexpect?


Source: (StackOverflow)

Extending the Python interactive shell

I'd like to extend the Python interactive shell to allow execution of non-python specific statements or commands. The idea being, if you type something on the prompt that would raise a NameError what you typed could be parsed for known external commands, and only it failing to find an external command, raise the NameError.

I'm not quite sure where to start, I tried calling code.InteractiveConsole().interact() inside a try: / except NameError but that didn't work

I read the documentation for the cmd module, but I looks like its designed JUST for calling external commands and ignores python statements.

The goal is a simple (its for a very small, GUI-less system) command shell that can be scripted with python (rather than sh)

Where should I be looking? A pure Python solution is ideal.


Source: (StackOverflow)

Change save path of PHP interactive shell history

I once found a way to disable session logging by php -a, php's interactive shell. How do I turn it back on? Is there a way to send logging to another, file besides ~/.php_history? I think I may have sent the output to /dev/null.

edit: It apparently still saves to the .php_history file. It doesn't save until you exit completely from the shell. I would still like to know how move the history logging to another file.


Source: (StackOverflow)