In Operating System
concept i want to write a C program
to make Unix
command works as DOS
commands.
It Means when ever i press Unix Command like ls
-which is used for Display list of Files
- it works like Dir
command in DOS
.Could you please help me out with this?
Asked
Active
Viewed 205 times
0

EniGma
- 2,444
- 4
- 22
- 33
-
Most shells have the `ls` command built-in, and it often contain many options to control its output. So what you should do is create a shell alias to add the options you want for the format you want. – Some programmer dude Mar 27 '15 at 09:48
-
`ls -l | awk '{printf "%s %s %s %20d %s\n", $6, $7, $8, $5, $9}'` – pmg Mar 27 '15 at 10:04
-
1You can study source code of the [win-bash - "A stand-alone bash for Windows"](http://win-bash.sourceforge.net/) or [Cygwin - "Get that Linux feeling - on Windows"](https://cygwin.com/index.html) projects. They do what you want to build, but in a more complete and more complicated way than "_practice and write a c program to do so_". Studying similar/competitor's source code is good way to find out how to implement things – xmojmr Mar 27 '15 at 12:57
1 Answers
2
Starting with the ls command as example, take input from user for the command. If the command is ls call a windows function that will display the content of the current working directory(). For ls,
- you need to get first the current working directory. GetCurrentDir() for windows will be your first step. This will help How do I get the directory that a program is running from?
- Then you can list the files in directory like this https://msdn.microsoft.com/en-us/library/windows/desktop/aa365200(v=vs.85).aspx. But you do need the output of first step.
Other commands can also be implemented like this

Community
- 1
- 1

Yasir Majeed
- 739
- 3
- 12
-
-
No `alk`, I just want to practice and write a c program to do so, if i can!!!.and i would appreciate to help me out with this.thanks – EniGma Mar 27 '15 at 10:36
-
1Look at the title, Run unix commands to DOS. Then it must be in windows – Yasir Majeed Mar 27 '15 at 10:37
-