executeShell doesn't work but system does

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 27 04:28:51 PDT 2016


On 6/26/16 12:02 PM, ag0aep6g wrote:
> On 06/26/2016 05:37 PM, Smoke Adams wrote:
>> system("cls") works but executeShell doesn't. system is depreciated.

Use spawn-related function, and avoid capturing output instead. Not sure 
if you need to call spawnShell (which creates a new system shell to 
execute the command), it depends on whether cls is a shell builtin or an 
executable.

>
> Unsolicited spelling correction: no 'i' in "deprecated".
>
>> What's going on? The docs say that it creates a new process. I simply
>> want to clear the console!
>
> `system` directly prints its output, `executeShell` returns it in a
> tuple with the status code. Maybe cls works by printing some specific
> clear code. If so, you have to print the output of the command.

Perhaps not exactly correct, but close enough. When you call 
"executeShell", the subprocess is started with stdout/err sent to a 
pipe, and no console is passed to the subprocess. Probably cls sees it's 
not talking to a console and exits.

-Steve


More information about the Digitalmars-d-learn mailing list