Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!samsung!brutus.cs.uiuc.edu!apple!motcsd!hpda!hpcupt1!swh From: swh@hpcupt1.HP.COM (Steve Harrold) Newsgroups: comp.lang.c Subject: Re: TurboC again Message-ID: <5940017@hpcupt1.HP.COM> Date: 31 Jan 90 15:52:37 GMT References: Organization: Hewlett Packard, Cupertino Lines: 31 Re: TurboC problem >>> The statement: >>> >>> system("sort c:\\directory\\filename.ext"); >>> >>> causes some odd behaviour. The applications spawns to the DOS level, but >>> does not execute the command... ---------- The problem lies in the fact that the "system()" call executes the named program directly without benefit of the "command.com" shell. Because of this, the file redirection intent is not handled by a shell; the "sort" program sees the "<.." and ">.." strings as parameters, which it does not know what to do with. If a shell were present, it (the shell) would process the "<.." and ">.." strings, remove them from the command line, and assign the named files to "stdin" and "stdout". The "sort" program would perceive no parameters. To achieve the intended file redirection you would have to either 1) use something like system("command /c sort <... >..."); 2) or, use the dup() and dup2() library routines to re-assign where "stdin" and "stdout" are to come from before using the simpler system("sort") ; Hope this helps.