How to run batch code in C++?

Hello EE,
how to run bath code in a C++ application?
i tried with the system function  Ex sysytem("batch code inside here")
 but i didn't get my hoped results..
kagami01Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CSecurityConnect With a Mentor Commented:
I compiled and run this code in Borland 5.02 and Dev-C++ and result:
Ok.

Ok.

Press any key to continue...

here works. It's very strange. maybe you have a mistake in type!
so I suggest you copy paste my first system calling.
BTW, if netsh doesn't work you should look why netsh dont work not system function
Regards
#include <windows.h>
 
int main()
{
system("netsh firewall add portopening TCP 6666 Firewall");
system("netsh firewall delete portopening TCP 6666");
system("pause");
}

Open in new window

0
 
Anthony2000Commented:
0
 
kagami01Author Commented:
this guide is for Visual C++.i have dev c++ as my c++ compiler.is it different??
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Anthony2000Commented:
I think system() is available for dev c++. Give it a try.  It will either compile and link or ...
0
 
CSecurityCommented:
include windows.h in your Dev-C++
call system function:
system("pause"); //for example
it SHOULD work. I have a suggestion for you:
after system("your batch file");
add system("pause") to see error.
I think your problem is in directory.
can you give me your system() function call?
Regards
0
 
kagami01Author Commented:
system(reg "add here the patch")
i got tons of error anyway
0
 
CSecurityCommented:
would you please send me your code without change?
if dont want to send your code, so please send me your system calling line (without change please)
Regards
0
 
kagami01Author Commented:
this is the code that i want to run but it didn't work with the function system();
netsh firewall add portopening TCP 6666 Firewall
0
 
kagami01Author Commented:
why you have inserted system(""netsh firewall delete portopening TCP 6666");?
0
 
kagami01Author Commented:
I tried that code below here but it didn worked for me
i tried to type even via cm.exe
system("netsh firewall add portopening TCP 6666 Firewall > nul\0");

Open in new window

0
 
CSecurityCommented:
nothing, because I compiled the code and want to clean new netsh insert!
forget it
Regards
0
 
kagami01Author Commented:
i see,anyway i inserted the code but nothing has happened i mean i got the "OK"
but nothing happened i mean the firewall has not changed or inserted my apllication.
please try to run this:
netsh firewall add portopening TCP 6666 Firewall > nul\0
wich error did u get?
0
 
CSecurityCommented:
I tried exactly this code:
system("netsh firewall add portopening TCP 6666 Firewall > nul\0");
and no error, compiled successfully but did not print OK
what is nul\0 ?!!
as I told you, if netsh does not work, does not mean that system doesn't work. system surely works. you should find a solution for netsh not for system function
Regards
0
 
kagami01Author Commented:
yeah u are right,anyway the firts point that we got it's that system("batch file inside here"); works for runs batch code in C++.
i take nul\0 from a C code
but in that source it worked smootly.
0
 
CSecurityCommented:
-> but in that source it worked smootly.
so, problem solved?
0
 
kagami01Author Commented:
ooops i meant in the C code not in C++ code
i used that for a winsock connection but not that i have the application in C++ with a ftp uploading function the code doesn't work.
0
 
CSecurityCommented:
puffff!! no idea my friend! no idea...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.