我试图创建一个程序,它将计算目录的数量或可读/可写/可执行文件的数量。用户只输入作者姓名和字母“d”,“r”,“w”或“x”。我试图在程序中直接调用“ls -l”,但这导致了一个错误。如何在C程序中调用UNIX命令?C - 程序中的UNIX命令
0
A
回答
1
我试着直接在我的程序中调用“ls -l”,但是这导致了错误。如何在C程序中调用UNIX命令?
您可以在SE C程序system
,例如:
system("ls -l");
对于工作,你还需要#include <stdlib.h>
+0
我认为在这种情况下程序输出也是必要的。 –
+0
在这种情况下,使用'popen' – immibis
0
使用find命令可能会更好地工作,你可以使用命令“find。-td | wc -l”来计算目录,并为具有相应标志的文件执行类似操作。
相关问题
- 1. ps命令linux vs unix在c程序中的不同行为
- 2. 来自C#的Unix命令
- 3. 使用命令行的Unix程序
- 4. 命令行应用程序:Unix的cd命令
- 5. Unix命令tr -c用法
- 6. UNIX中执行的命令C
- 7. C代码中的Unix命令
- 8. unix中排序命令的性能
- 9. SSH UNIX命令
- 10. Unix顶部命令列选择与另一个C程序?
- 11. 如何调用UNIX从C程序命令
- 12. Unix strace命令
- 13. 转义序列Perl的Unix命令
- 14. Windows中的ctime unix命令
- 15. python中的Unix命令与&
- 16. UNIX中的杀死命令
- 17. Groovy中的Unix FIND命令
- 18. Perl中的Unix命令?
- 19. Unix中的屏幕命令
- 20. Unix命令
- 21. Unix grep命令
- 22. Unix命令
- 23. Unix dot命令
- 24. Unix命令
- 25. unix find命令
- 26. tee命令UNIX
- 27. unix bash命令
- 28. unzip unix命令
- 29. 狗命令UNIX
- 30. UNIX grep命令
看看'system()' – Haris
虽然['system()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html)'有效',你必须制造仔细的命令行;启动程序无法过滤输出(在正常情况下)。您可能需要使用POSIX函数['popen()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/popen.html),或者['fork()'](http:// pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html)和['execvp()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/execvp.html)及相关函数(' pipe()','dup2()',...)。 –
您可能还想研究POSIX函数['nftw()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/nftw.html), ['opendir()'](http:/ /pubs.opengroup.org/onlinepubs/9699919799/functions/opendir.html), ['readdir()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html), [ 'STAT()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/stat.html)。 –