943,831 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1351
  • C++ RSS
Dec 15th, 2008
0

keytool in .bat file not working

Expand Post »
Hi,

The was my application works is that my C++ .exe will create a .bat file, which will then in turn run the .bat file.

C++ Syntax (Toggle Plain Text)
  1. ofstream myfile ("tmp.bat");
  2. if (myfile.is_open())
  3. {
  4. myfile << "keytool –import –alias exe –file cert.cer –key example\n";
  5. myfile.close();
  6. system("tmp");

The batch file is created, however does not run this keytool command correctly.

The important thing here is that if I go and manually edit that batch file created by my .exe, it works. If I delete all spaces in the command e.g keytool<del here>-import and re-space, it works??

Is there some sort of "whitespace" that I am not aware of??

Note: Some code removed.

Thanks for your help in advance!
Last edited by darren2005; Dec 15th, 2008 at 6:35 pm.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
darren2005 is offline Offline
58 posts
since Mar 2007
Dec 15th, 2008
0

Re: keytool in .bat file not working

The problem could be the difference in environment variables or current working directory. In the system() line try adding the full path to that batch file and see if that works.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,951 posts
since Aug 2005
Dec 16th, 2008
0

Re: keytool in .bat file not working

The problem could be the difference in environment variables or current working directory. In the system() line try adding the full path to that batch file and see if that works.
Ok - will try this, however the .exe does run the .bat file with no problems. It does execute other commands in that .bat (SET CLASSPATH & SET PATH, etc) file but not the above KEYTOOL command?

Do you know if C++ has an issue with ( - ) as it does with ( \ )??

Update - It seems to be an issue with the ( - ) part of the command. If C++ writes this .bat file with the keytool command using for example keytool -import it does not process this command. However, if I delete the ( - ) part and re-enter it, it works.
Last edited by darren2005; Dec 16th, 2008 at 7:07 am.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
darren2005 is offline Offline
58 posts
since Mar 2007
Dec 16th, 2008
0

Re: keytool in .bat file not working

>>however the .exe does run the .bat file with no problems
Then don't bother with my suggestion.

Sounds like the problem is with the program keytool. Open the batch file with Notepad.exe, copy the line into clipboard, create a command prompt, paste that line into the cmd prompt and then execute it. Does it work?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,951 posts
since Aug 2005
Dec 16th, 2008
0

Re: keytool in .bat file not working

>>however the .exe does run the .bat file with no problems
Then don't bother with my suggestion.

Sounds like the problem is with the program keytool. Open the batch file with Notepad.exe, copy the line into clipboard, create a command prompt, paste that line into the cmd prompt and then execute it. Does it work?
Yes - that does work. Does C++ have any issues writing a ( - ) to a text/bat file?
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
darren2005 is offline Offline
58 posts
since Mar 2007
Dec 16th, 2008
0

Re: keytool in .bat file not working

Without putting both versions of the .bat file into a hex editor, it's hard to see what could be wrong.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 16th, 2008
0

Re: keytool in .bat file not working

Click to Expand / Collapse  Quote originally posted by Salem ...
Without putting both versions of the .bat file into a hex editor, it's hard to see what could be wrong.
I do understand - Just thought that someone would have an idea as to what could cause the issue.

The .bat file looks and acts fine until it comes down to the KEYTOOL command. Just does not like the ( - ) part of the command?

Is there anything I could do in order to gain a better debugging experience with regards to the .bat file? Any application that would show some kind of invalid character or invisible whitespace?
Last edited by darren2005; Dec 16th, 2008 at 1:25 pm.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
darren2005 is offline Offline
58 posts
since Mar 2007
Dec 16th, 2008
0

Re: keytool in .bat file not working

To be honest, your "symptom" and your "fix" don't make a lot of sense to me. You're doing what I would consider to be the obvious thing to try first (in the C++ code).

system("cmd /c tmp.bat");
might be a more explicit way of running the batch file.

As for editors, try this
http://notepad-plus.sourceforge.net/uk/site.htm
It comes with a "hex" viewer, so you can see exactly what bytes are in the file. It's also a pretty useful text editor as well
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 16th, 2008
0

Re: keytool in .bat file not working

Click to Expand / Collapse  Quote originally posted by Salem ...
To be honest, your "symptom" and your "fix" don't make a lot of sense to me. You're doing what I would consider to be the obvious thing to try first (in the C++ code).

system("cmd /c tmp.bat");
might be a more explicit way of running the batch file.

As for editors, try this
http://notepad-plus.sourceforge.net/uk/site.htm
It comes with a "hex" viewer, so you can see exactly what bytes are in the file. It's also a pretty useful text editor as well
Thanks for help - will try what you suggested with the system cmd and the text editor

Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
darren2005 is offline Offline
58 posts
since Mar 2007
Sep 27th, 2011
-1

Answer

There is someone telling about here: http://stackoverflow.com/questions/7...in-batch-files
Last edited by metoohere; Sep 27th, 2011 at 2:18 pm.
Reputation Points: 6
Solved Threads: 0
Newbie Poster
metoohere is offline Offline
1 posts
since Sep 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: iomanip for c++ calendar
Next Thread in C++ Forum Timeline: Visual Studio Performance





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC