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?
1 Answer
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
4 Comments
alk
Are you sure the OP want to create the program under windows?
EniGma
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.thanksYasir Majeed
Look at the title, Run unix commands to DOS. Then it must be in windows
EniGma
sorry, yes it is in windows :(
lscommand 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.ls -l | awk '{printf "%s %s %s %20d %s\n", $6, $7, $8, $5, $9}'