0

I want to launch a PHP Process in a Screen session that has not been invoked yet. I do not want to attach to this screen. I will be launching lots of these, by hand at first, then probably with a shell script. I would like to write the output of each to a unique log file ( preferably in /tmp/shell ), but it really doesn't matter where.

This seems close to what I want, but doesn't work:

screen -d -m -X 'php process.php param1 param2'

SOLUTION

Just remove the -X.

This works screen -d -m php process.php param1 param2

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
T. Brian Jones
  • 13,002
  • 25
  • 78
  • 117
  • 1
    Does anything here answer your question? http://serverfault.com/questions/104668/create-screen-and-run-command-without-attaching – merlin2011 Jan 26 '14 at 22:09

1 Answers1

1

I think you need to skip -X:

screen -d -m 'php process.php param1 param2'

It's also useful to give the session a name, especially if you're starting several:

screen -d -m -S mysession 'php process.php param1 param2'

-X is for sending commands to screen itself.

See also: this QA here on SO

Additional explanation

The started screen session will only exist as long as your command is running. When php process.php ... exits, screen will also exit.

Community
  • 1
  • 1
grebneke
  • 4,414
  • 17
  • 24
  • `screen -d -m` creates a new Screen session, but obviously doesn't start anything in it. `screen -d -m 'php process.php param1 param2'` fails to start a new Screen session for me. The command executes without any output. – T. Brian Jones Jan 26 '14 at 22:23
  • 1
    @T.BrianJones - Maybe some problem running php. Try another command, like `screen -d -m top`, then `screen -r` and `top` should already be running. I use this all the time. – grebneke Jan 26 '14 at 22:25
  • @T.BrianJones - If `php` exits, `screen` will also exit. Example: `screen -d -m date` will exit immediately so cannot be resumed. – grebneke Jan 26 '14 at 22:27
  • I was mistaken. This works fine for PHP processes ... `screen -d -m php process.php` – T. Brian Jones Jan 26 '14 at 22:44