To try to determine the window width, this patch which uses the "mode con" command was committed:
#1078514: Determining the number of columns on Windows
In bootstrap.inc:
if (!($columns = getenv('COLUMNS'))) {
// Trying to export the columns using stty.
exec('stty size 2>&1', $columns_output, $columns_status);
if (!$columns_status) $columns = preg_replace('/\d+\s(\d+)/', '$1', $columns_output[0], -1, $columns_count);
// If stty fails and Drush us running on Windows are we trying with mode con.
if (($columns_status || !$columns_count) && drush_is_windows() && version_compare(phpversion(), '5.3.0') > -1) {
$columns_output = array();
exec('mode con', $columns_output, $columns_status);
if (!$columns_status && is_array($columns_output)) {
$columns = (int)preg_replace('/\D/', '', $columns_output[4], -1, $columns_count);
}
}
// Failling back to default columns value
if (empty($columns)) {
$columns = 80;
}
}
Alas on Windows 7, there apparently is no mode command. I tried cmd, powershell, and cygwin. On my Vista machine, it does work with powershell. There is a test for PHP version. I'm wondering if this was actually related to windows version?
The support solution is to simply define a windows environment variable of COLUMNS and whatever number you want. (If you set it wider than 80, then adjust the shell's properties by clicking on the icon in the title bar of the shell window.)
I'm not sure what to suggest, other than to perhaps issue a message to suggest setting COLUMNS as an environment variable, should mode not return the desired result. Maybe something to the effect of "Your terminal window does not support the 'mode' command which Drush uses to set the column width of its output. To avoid this message, set a Windows Environment named COLUMNS=80 (or other desired value) to avoid this message." Hideous, I know.
Comment | File | Size | Author |
---|---|---|---|
#10 | drush-node_error_warning-1899598-10.patch | 599 bytes | DanChadwick |
#6 | drush-suppress_mode_error-1899598-6.patch | 730 bytes | DanChadwick |
Comments
Comment #1
greg.1.anderson CreditAttribution: greg.1.anderson commentedHm, it's been a while since I've fired up Windows 7, but I could have sworn that mode worked there for me.
If mode does not work, I am not very fond of the idea of Drush printing a warning message every single time. I think that leaving the default behavior of always wrapping to 80 columns, with perhaps an addition to the documentation, would be better. (Docs patches welcome.)
Anyone in Windows land have any extra info or advice on column detection on that platform?
Comment #2
DanChadwick CreditAttribution: DanChadwick commentedWell the message would be no worse than the "mode is not a recognized command" error that you get with every Drush command. ;) At least one could fix the problem, which would both give the option of setting the columns and silencing the message.
Or is there a way to call exec and suppress the error to the console? That would work too.
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedYes, I agree that the error message should be suppressed when the mode command is missing.
exec('mode con 2>/dev/null', $columns_output, $columns_status);
might do the trick there.Comment #4
DanChadwick CreditAttribution: DanChadwick commented#3 works in so far as it avoids the message. Assuming Greg has confirmed that it works when mode is available, I'd say #3 is RTBC.
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedSetting status to 'active', since there is no patch, but I agree that if
mode con 2>/dev/null
still works fine on systems with the mode command, that this change could be easily committed.Comment #6
DanChadwick CreditAttribution: DanChadwick commented@greg -- sorry. I misunderstood your workflow (since it was your idea and you're a co-maintainer). Here's a patch. Thanks for your help on Drush.
I changed the status back to needs review, although maybe it should be RTBC.
Comment #7
greg.1.anderson CreditAttribution: greg.1.anderson commentedrtbc after it has been tested on a windows system with the mode command. I will help out here when I have time, but I'm slammed right now, and I don't usually work on Windows systems. Setting status to strict definition allows others to see what stage the issue is at, so they can pitch in if desired.
Comment #8
DanChadwick CreditAttribution: DanChadwick commentedOn Windows 7:
- MinGW32:
-- mode doesn't work
-- 2>/dev/null results in no error message
-- 2>nul results in no error message
- PowerShell
-- mode doesn't work
-- 2> error redirection seem to work regardless of target (even a valid filename). An error is generated.
- Cygwin
-- mode doesn't work
-- 2>/dev/null results in no error message
-- 2>nul results in an actual nasty file named 'nul', which Cygwin can delete, but the windows explorer can't delete or rename.
On Windows Vista:
- MinGW32: same as Windows 7
- PowerShell
-- mode does work
-- 2> error redirection to either null device doesn't work; an error is generated
-- 2> error redirection to a file does work (creates an empty file with no error)
- Cygwin: same as Windows 7
Based on this and absent further info, I would suggest that a message be displayed should 'mode con' fail. At least the user can then add the COLUMNS environment variable to both suppress the message and get the functionality they want.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedSince it's hard to correctly suppress the error message for all shells and all platforms, I agree that a message is okay. I'll commit any submitted patch for Windows that does this after I test on Linux (which should behave the same, since all code is inside a drush_is_windows() test).
Comment #10
DanChadwick CreditAttribution: DanChadwick commentedThe message says:
Comment #11
greg.1.anderson CreditAttribution: greg.1.anderson commentedCommitted to 8.x-6.x and 7.x-5.x. Thanks.