vscode-php-debug
vscode-php-debug copied to clipboard
Pass file content as stdin input
I believe that it is currently not possible to pass the contents of a file as stdin input for CLI executions.
I tried...
"externalConsole": true,
"args": ["<", "input.txt"]
# and with:
"args": ["<", "${fileDirname}/input.txt"]
... but the debug hangs waiting for an input.
Hi!
This will not work like that, because the debug adapter (this extension) spawns a php process and gives it the parameters.
If you look at the last section of https://github.com/xdebug/vscode-php-debug#supported-launchjson-settings there is a section "Options specific to CLI debugging". When starting a debug process, the following happens:
Working directory: $cwd Process spawned: $runtimeExecutable Arguments: $runtimeArgs $program $args Environment variables: $env
So you could get the debug adapter to spawn shell and get it to use a file as stdin.
I can make a working example at a later date as I am currently traveling.
Alternatively I would suggest to use "Listen for Xdebug" and run your program in a separate shell. Set the XDEBUG_MODE env to debug.
XDEBUG_MODE=debug php script.php < input.txt
Let me know if you are able to solve the problem like this.
Alternatively I would suggest to use "Listen for Xdebug" and run your program in a separate shell. Set the
XDEBUG_MODEenv to debug.
XDEBUG_MODE=debug php script.php < input.txtLet me know if you are able to solve the problem like this.
Yes, that way worked. I used the "Listen for Xdebug" setting in vscode.
export XDEBUG_MODE=debug
php script.php < input.txt
Great! I'll try to write a configuration with shell when I come back from my travels.
Here is an option:
{
"name": "TEST",
"type": "php",
"request": "launch",
"cwd": "${workspaceFolder}",
"port": 0,
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
"runtimeExecutable": "bash",
"runtimeArgs": [
"-c",
"php -dxdebug.start_with_request=yes script.php < input.txt"
]
}
Thanks, It works! I made some changes for flexibility with script name or input location in case of using an external terminal.
{
"name": "Launch currently open script with input",
"type": "php",
"request": "launch",
"cwd": "${fileDirname}",
"port": 0,
"runtimeExecutable": "bash",
"runtimeArgs": [
"-c",
"php -dxdebug.start_with_request=yes ${file} < ${cwd}/input.txt"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}