0

I need to complete a script which gets a username from terminal to a php script and then deletes the user's comments.

So I am wondering how the username should be read by the php script, the same way that one can read a value in a bash script.

Thanks

1
  • What do you want to achieve? Pass the script a user name on the command line or have the script asking you for the user name while it's running. If it's not to many users you could also show a list of users and let the administrator choose. Of course this options do not exclude each other.
    – BetaRide
    Dec 20 '11 at 7:34
4

In your Drush command you need to call drush_get_option('myoption'); to get the value of an input parameter.

To call your Drush command you need to specify your input option as below:

drush mycommand --myoption=myvalue

1

there is an example command in the drush directory : http://drupalcode.org/project/drush.git/blob/refs/heads/7.x-4.x:/examples/sandwich.drush.inc

in the command hook you define your arguments and those are then passed to the function that implements the command

0

If you implement a drush command, you can call that via the command line and define arguments and switches.

You can easily then hook into drupal. as your function can run from a bootstrapped drupal instance.

1
  • I know that I should use drush. The problem is that how to define the STD input in the php/drush script.
    – alfish
    Aug 21 '11 at 23:28
0

In answer to the question by "alfish"

I think the ultimate answer to this "old" question is to use PHP to control stdin.

function ask_user_name() {
  print("Please input your name: ");

  $handle = fopen ("php://stdin","r");
  $line = fgets($handle);

  drush_print("Your name is $line");
}

Basically there was no need to establish an interface mechanism in drush since it already exists in php... but Drush does provide four commands anyway.

  • drush_choice
  • drush_choice_multiple
  • drush_confirm
  • drush_prompt

So in using drush_prompt you would do something like this.

function ask_user_name() {
  $result = drush_prompt("Please input your name",NULL,TRUE);
  drush_print("Your name is $result");
}

I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.