简体   繁体   English

如何使Ubuntu命令在Windows上运行

[英]How to make Ubuntu commands make work on Windows

My C code which runs on Ubuntu has line 我在Ubuntu上运行的C代码行

system("ls -l | wc > temp.txt");

I want to make it work on windows so that It has to be OS Independent.How can I do that. 我想使其在Windows上运行,因此它必须与OS无关,我该怎么做。 Can any one help me? 谁能帮我?

I would guess that the particular code shown is probably going to get the first value from the "temp.txt" file at some point and use it as a count of files (actually number of files plus one) 我猜想显示的特定代码可能会在某个时候从“ temp.txt”文件中获取第一个值,并将其用作文件计数(实际上是文件数加一个)

Instead of that you could use C code like this 取而代之的是,您可以像这样使用C代码

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

int main() {
DIR *cwd;
int c=1; /* like +1 */
struct dirent *d;
if ((cwd=opendir(".")) ) {
 while((d=readdir(cwd))) {
     if (*(d->d_name) != '.') c++; /* ignore dot files */
 }
} else {
    perror("opendir fail");
    return(1);
}
printf("the first number in temp.txt would be %d", c);
return(0);
}

Whatever the system() call result is doing, this is my answer: rewrite it in C, which you have working on both systems 无论system()调用结果在做什么,这都是我的答案:用C重写它,您在两个系统上都使用过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM