Run batch file from a c progam in linux

Hi, this is going to sound like a pointless question since it should be easily tested myself, but here me out first.

Can you use the following command in a C program to run a batch file in Linux?

system("example.bat");

I can't test it out myself since I'm ssh'ing into a linux server remotely from my windows computer, and the server blocks me from doing stuff with a batch. I could also seemingly just wait til Monday when I can use a school computer, but time is of the essence and I really need to know that it works before then.

Thank you.
system("example.bat");

I can't test it out myself since I'm ssh'ing into a linux server remotely
system() calls the shell to run the specified program. Common *nix shells won't run Windows batch files.
you can run the unix version, a shell script, using system. If the security prevents it, you cannot, though. It would be very odd to do that on unix; the os still relies on scripts and console programming at its core and blocking that would mean you have a useless unix shell. I don't think the os can tell between the program calling it and you calling it, is why.... and they *have* to let all but the most untrusted users run scripts.
I have no choice but to go to college after hours and test it on their machines then.
It'll either work for me or I have something wrong in the code. There's all sorts of student rights about fair challenges, and assigning something we have no way of testing would break pretty much all of them.


Side note, I have never felt much like a computer scientist til we started working in terminal. Makes you feel good when stuff happens.
I have no choice but to go to college after hours
You should ask the sysadmin about remote logins.
Last edited on
If you have a spare disk partition somewhere, you could install Linux on it.

There are various partition altering software, which can shrink an existing partition without losing any data.

Or even install Linux on a USB stick - it's slower to get started, but at least one can play around a bit.

How about a Linux VM running under windows?

Hope all goes well :+)

I wonder if QNX still has that <2MB unix disk...
Last edited on
Hey, so. I misunderstood the instructions. The simulated shell is to have 2 modes: interactive and batch. When it said user choice, I assumed you programmatically made a menu where the user got to choose 1 for interactive, 2 for batch.

That was wrong. I wasn't aware that you can have a c program program.c and a batch file ba.sh
and be able to do ./program ba

...or is it ./program ba.sh?

I'll have to tinker to be sure. Anyhow, the user chooses by how they run it on the command line.

*edit*

./program ba.sh

I wondered why he wanted us to have a main with arguments. This explains it.
Last edited on
and the server blocks me from doing stuff with a batch.
That's probably not the case. I expect you're trying to run Windows shell commands on Linux. You need to run Linux commands on Linux.
You're correct. I was confused about directions.
Registered users can post here. Sign in or register to post.