1

I have a shell script which requires users input ("Please select y/n:" etc.)

I would like this to be executed through a webpage.

Any ideas on how i can do this? I have tried php shell_exec... but it just executes the commands and doesn't prompt for input.

Not sure if this is possible... But any help would be greatly appreciated.

Cheers

1

3 Answers 3

1

Typically the user input would be using HTML/Javascript. The input is then posted to the URL ( a PHP script for example) which then processes the input and executes the script.

Sign up to request clarification or add additional context in comments.

Comments

0

enter code hereCheck the script to see if there are any flags to force the script to run without user input. Typically you can bring up help by writing something like:

yourscript /h

or

yourscript --help

There might be a flag for that. Look for information about "force" or "prompt" in the help. If not available you could, if you are on a Linux/Unix environment, make a new script that sends the input to your other script. Unsure if that works on Windows though.

Here's a very simple example:

    echo y | yourscript

Comments

0

The only way you can do this is recreating the config part of the CLI tool in a form of HTML, e.g.:

<form method="POST" action="/foo.php">
  Please select:
      <input type="radio" name="yesno" value="1">yes
      <input type="radio" name="yesno" value="0">no
  Some other option:
      <input type="text" name"someoption">
</form>

Afterwards you need to create a foo.php that will handle the input part with HEREDOC, e.g.:

<?php
    $aData = some_validation_and_data_preparation_method($_POST);

    $sCmd = implode("\n", $aData);

    $sOutput = shell_exec("./some_cli_tool << EOF
{$sCmd}
EOF");

    print $sOutput;

Notice the lack of indentation on the actual HEREDOC (i.e. between the EOF markers).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.