Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
June 26, 2016 executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
system("cls") works but executeShell doesn't. system is depreciated. What's going on? The docs say that it creates a new process. I simply want to clear the console! |
June 26, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to "Smoke" Adams | On 06/26/2016 05:37 PM, Smoke Adams wrote: > system("cls") works but executeShell doesn't. system is depreciated. 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. This works with `clear` on Linux which seems to behave similarly to Windows' cls: ---- void main() { import std.stdio: write, writeln; import std.process: executeShell; import std.exception: enforce; writeln("A"); auto r = executeShell("clear"); enforce(r.status == 0); write(r.output); writeln("B"); } ---- `wait(spawnShell(...))` is the other suggestion from `system`'s deprecation message. It works for `clear`, too: ---- void main() { import std.stdio: writeln; import std.process: spawnShell, wait; writeln("A"); wait(spawnShell("clear")); writeln("B"); } ---- |
June 26, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to "Smoke" Adams | On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote: > system("cls") works but executeShell doesn't. system is depreciated. > > What's going on? The docs say that it creates a new process. I simply want to clear the console! I have problem with executeShell on windows 10 (LDC 1.0.0) too. When I rewrote it into http://prntscr.com/blc9j8 it works. |
June 26, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to Satoshi | On Sunday, 26 June 2016 at 17:56:08 UTC, Satoshi wrote:
> On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote:
>> system("cls") works but executeShell doesn't. system is depreciated.
>>
>> What's going on? The docs say that it creates a new process. I simply want to clear the console!
>
>
> I have problem with executeShell on windows 10 (LDC 1.0.0) too.
> When I rewrote it into http://prntscr.com/blc9j8 it works.
OT but please, refrain from using screenshots. I know it's very customary on windows but I can't copy paste code from a screenshot to play with it and manually copying is error-prone. We manipulate text, let's stay with it.
|
June 27, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | 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 |
June 27, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | On Sunday, 26 June 2016 at 19:01:07 UTC, cym13 wrote: > On Sunday, 26 June 2016 at 17:56:08 UTC, Satoshi wrote: >> On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote: >>> system("cls") works but executeShell doesn't. system is depreciated. >>> >>> What's going on? The docs say that it creates a new process. I simply want to clear the console! >> >> >> I have problem with executeShell on windows 10 (LDC 1.0.0) too. >> When I rewrote it into http://prntscr.com/blc9j8 it works. > > OT but please, refrain from using screenshots. I know it's very customary on windows but I can't copy paste code from a screenshot to play with it and manually copying is error-prone. We manipulate text, let's stay with it. Sorry... It's same function as executeImpl just with changed byChunk to 1. It corrupt stack when I called the original function. https://github.com/ldc-developers/phobos/blob/aa133b5927bbc5f9669374d5bb0f206f6f68cfe4/std/process.d#L2130 |
June 27, 2016 Re: executeShell doesn't work but system does | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Sunday, 26 June 2016 at 16:02:18 UTC, ag0aep6g wrote:
> On 06/26/2016 05:37 PM, Smoke Adams wrote:
>> [...]
>
> Unsolicited spelling correction: no 'i' in "deprecated".
>
>> [...]
>
> `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.
>
> [...]
neither work but
wait(spawnShell("cls"));
|
Copyright © 1999-2021 by the D Language Foundation