Call command line from C program

2019-04-29 20:59发布

I am writing an command line application in C and from within the program, I would like to call other command-line applications. For example (and only as a clear example!), say the I would like to write a C app that calls the java compiler. For one, how would I do this? Is there a C function that directly calls the command line of something? For two, how would I take the normal text output that the java compiler displays and display it through the c program?

I'm sorry if this sounds a bit crazy, but I am very new to C and I have never done anything like this before. I would love to start writing a few of these utility style apps. If it matters any, I am currently running Windows, but would prefer a platform-independent method if possible, as I do use Linux from time to time.

2条回答
Deceive 欺骗
2楼-- · 2019-04-29 21:33

You might look into system. I think you can use it in Windows as well as UNIX/Linux systems.

查看更多
Summer. ? 凉城
3楼-- · 2019-04-29 21:39

Use the right tool for the job. C is not meant for programming this sort of 'utility'. Use either a shell scripting language, or something like Python or Perl.

查看更多
登录 后发表回答