
Porting C programs from Windows to Unix?Dave, I read your books Teach Yourself Unix in 24 Hours and Wicked Cool Shell Scripts and since then I can't imagine working again on a system like windows! 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
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Unix and Linux Help
, Windows Help
(Article 3944)
Tagged: Previous: How do I cancel my America Online (AOL) account? Next: iTunes ported to Sony PSP? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Something is not very clear to me. I kinda wondered about that myself, Martin. My conclusion is that he's trying to convert his C programs within the Windows environment before he ports them to Unix. Posted by: Dave Taylor at April 2, 2005 2:57 PMAnother possibility is that he's looking for the shell command ("cmd" in Windows) which, depending on the shells available will be one of "sh", "csh", "ksh", "tcsh", etc. (Bourne, C-Shell, Korn, etc) This matches the example that was provided. I have existing GUI SDK/C program in windows. Thanks i have a c program which is running under linux operating system . i wish to run the same c program under windows operating system what the steps i need to follow to run the same c code on windows platform . i am using windows xp the program is connecting the medical device to pc and reading the data onto the server thanks i have c program which is running on linux operating system want to run on windows operating system the program is successfully executing the code on linux operating system
thanks i have c program which is running on linux operating system want to run on windows operating system the program is successfully executing the code on linux operating system
thanks Hello Dave and Team. In the past I've found many helpful articles on this site, nad have past along the wealth to many friends. I don't really have a technical question per-say, but more along the lines of looking for an opinion. Some time ago I found another project I'd like to have your thoughts on. UNIX's WINE project have started some time ago a new project called ReactOS, for a new Operating System. You can find it @: www.reactos.org I'd be currious to read your thoughts on the project, if of course your time allows it. Thx muchly in advance for your time and thoughts on the matter. Cheers, and keep up the great work. PS: When I complete my website, I'll most certainly add a link to yours. Posted by: Marc at November 9, 2007 7:37 PMI have linux c file which uses "system(cmdline)" and now I need to port it to Windows VC/C++. Thanks Barbara Posted by: Barbara Shi at January 9, 2008 3:01 PMi have c program which is running on linux operating system want to run on windows operating system the program is successfully executing the code on linux operating system Posted by: vipul patel at February 27, 2008 12:11 AMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|