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.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!

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.

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.

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

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

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

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?

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

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

;)

This article has been dead for over six months. Start a new discussion instead.