Sign in to follow this  

Sending info from c++ to .bat files?

This topic is 2844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if it was possible to send variables from my c++ program to a .bat file using Private Sub Command1_Click() char str1 = "Hello" Shell ".\rec.bat" & " " & str1", vbNormalFocus End Sub but i don't know what I would put in that batch file to get the varibles, and I don't even know if this is a way to go about doing that.

Share this post


Link to post
Share on other sites
Yeah, arguments to a batch file are accessible as %1, %2, etc. There are more advanced ways to use the arguments, but if all you want to do is give it a string, that's sufficient.

Share this post


Link to post
Share on other sites
Go read about pipes and redirection.

Observe this UNIX command:

cat file.stuff | strings > result.txt

Assuming that file.stuff contains both binary data with some text buried in it, this command sequence will extract the text into result.txt.

Here's how.

cat is a program that reads a file and dumps the output into standard output. The pipe symbol tells it to redirect that output into another program. strings can read that information through standard input, parse it to scrub any non-text data, and dump the result into standard output. The arrow redirects strings' output into a file.

In C++ you can access standard out, in and error with the cout, cin and cerr streams. You can do it with any other language too but the APIs will differ.

The syntax for using redirection in Windows is probably different but this post is just to let you know that these features exist. You'll need to look up how piping or redirection is done in the Windows command line (and thus bat files.)

EDIT: I just realized you said from C++ to .bat, not the other way around.

I'll leave this here though in case you think of something useful with it.

Also, that's not C++, that's Visual Basic.

Share this post


Link to post
Share on other sites
Quote:
Original post by Iiimage
can you explain a little bit, I've used batch files but I never have transfered data to them.


Quote:
Original post by Sneftel
Yeah, arguments to a batch file are accessible as %1, %2, etc. There are more advanced ways to use the arguments, but if all you want to do is give it a string, that's sufficient.


Share this post


Link to post
Share on other sites

This topic is 2844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this