954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

keytool in .bat file not working

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.

ofstream myfile ("tmp.bat");
  if (myfile.is_open())
  {
  myfile << "keytool –import –alias exe –file cert.cer –key example\n";
  myfile.close();
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.gkeytool-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!

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
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 examplekeytool -import it does not process this command. However, if I delete the ( - ) part and re-enter it, it works.

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 

>>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?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

>>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?

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 

Without putting both versions of the .bat file into a hex editor, it's hard to see what could be wrong.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
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?

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 

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 :)

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

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

;)

darren2005
Junior Poster in Training
58 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
 
metoohere
Newbie Poster
1 post since Sep 2011
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You