Solved

How to run batch code in C++?

Posted on 2008-10-01
17
686 Views
Last Modified: 2013-11-17
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..
0
Comment
Question by:kagami01
  • 8
  • 7
  • 2
17 Comments
 
LVL 8

Expert Comment

by:Anthony2000
ID: 22616644
0
 

Author Comment

by:kagami01
ID: 22616715
this guide is for Visual C++.i have dev c++ as my c++ compiler.is it different??
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 22617235
I think system() is available for dev c++. Give it a try.  It will either compile and link or ...
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 17

Expert Comment

by:CSecurity
ID: 22619895
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
 

Author Comment

by:kagami01
ID: 22622238
system(reg "add here the patch")
i got tons of error anyway
0
 
LVL 17

Expert Comment

by:CSecurity
ID: 22623166
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
 

Author Comment

by:kagami01
ID: 22624765
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
 
LVL 17

Accepted Solution

by:
CSecurity earned 130 total points
ID: 22624910
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
 

Author Comment

by:kagami01
ID: 22624962
why you have inserted system(""netsh firewall delete portopening TCP 6666");?
0
 

Author Comment

by:kagami01
ID: 22624990
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
 
LVL 17

Expert Comment

by:CSecurity
ID: 22625021
nothing, because I compiled the code and want to clean new netsh insert!
forget it
Regards
0
 

Author Comment

by:kagami01
ID: 22625118
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
 
LVL 17

Expert Comment

by:CSecurity
ID: 22625157
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
 

Author Comment

by:kagami01
ID: 22625257
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
 
LVL 17

Expert Comment

by:CSecurity
ID: 22625280
-> but in that source it worked smootly.
so, problem solved?
0
 

Author Comment

by:kagami01
ID: 22625372
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
 
LVL 17

Expert Comment

by:CSecurity
ID: 22625421
puffff!! no idea my friend! no idea...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 96
C++ :Change value from  DisableCMD registry 4 66
Re-position the objects 7 117
DCT of  2D array using fftw in c++ 9 69
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question