Porting C programs from Windows to Unix?
My problem is that I've started to make my C files Unix-compatible but I can't find a command for C in Windows that does the same thing as system("cmd") for Unix. Any suggestions?
This was a tough question, actually, because I haven't done any Windows-level C programming in, well, more years than I want to talk about. Let's just say it's been a rather long time. :-)
I do remember that the wonderful Unix system() call that makes it a breeze to invoke any other Unix command (or sequence of commands) from within a C program has no direct analog in the Windows programming world because of the fundamental differences in OS architecture.
To figure out how to best address this, I asked a couple of colleagues who are better versed in C / Windows programming, and here's what they had to say:
The system function executes an internal operating system command, or an .EXE, .COM (.CMD in Windows NT) or .BAT file from within a C program rather than from the command line.
The system function finds the command interpreter, which is typically CMD.EXE in the Windows NT operating system or COMMAND.COM
Your options for an analog to the Unix system call depend on how much work you want to undertake, and what you want to achieve. For total control, use the CreateProcess system call. It is low level, closer to the fork/exec level in UNIX. WinExec is a higher level function that is closer to system. You can also call system, but you have no control over console windows, window states, etc.
I hope those are helpful to you. If I bump into a better or more definitive answer, I'll post it as a comment, and, of course, it's quite possible that some other reader might have a better response that they can add here too!
Thanks to Ray Lischner, JP Morgenthal and Wayne Freeze for their assistance
More Useful Unix and Linux Help Articles:
✔ Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...✔ Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...✔ Can I script renaming files based on an XML data map?
I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...✔ Test for valid numbers in a Bash shell script?
In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...✔ Review: iSSH for the iPad/iPhone
If you're running an online business like I am, there are times when you need to connect and log in to the server...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
I do have a comment, now that you mention it!
Check This Out Too...
Look for Answers
All Our Categories
Apple iPad Help
Articles and Reviews
Auctions and Online Shopping
Blogs and Blogging
Building Web Site Traffic
Business and Management
Computer and Internet Basics
d) None of the Above
Google Gmail Help
Google Plus Help
Industry News and Trade Shows
iPhone and Cell Phone Help
iPod, Sony PSP and MP3 Player Help
Kindle Fire Help
Mac OS X Help
Pay Per Click (PPC) Advertising
Search Engine Optimization (SEO)
Shell Script Programming
Tech Support Video Help
The Writing Business
Twitter, LinkedIn and Social Network Help
Unix and Linux Help
Video Game Tips and Help
Windows PC Help
Find Me on Google+
ADT on G+