keytool in .bat file not working

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

keytool in .bat file not working

 
0
  #1
Dec 15th, 2008
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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: keytool in .bat file not working

 
0
  #2
Dec 15th, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: keytool in .bat file not working

 
0
  #3
Dec 16th, 2008
Originally Posted by Ancient Dragon View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: keytool in .bat file not working

 
0
  #4
Dec 16th, 2008
>>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?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: keytool in .bat file not working

 
0
  #5
Dec 16th, 2008
Originally Posted by Ancient Dragon View Post
>>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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: keytool in .bat file not working

 
0
  #6
Dec 16th, 2008
Without putting both versions of the .bat file into a hex editor, it's hard to see what could be wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: keytool in .bat file not working

 
0
  #7
Dec 16th, 2008
Originally Posted by Salem View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: keytool in .bat file not working

 
0
  #8
Dec 16th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 55
Reputation: darren2005 is an unknown quantity at this point 
Solved Threads: 2
darren2005's Avatar
darren2005 darren2005 is offline Offline
Junior Poster in Training

Re: keytool in .bat file not working

 
0
  #9
Dec 16th, 2008
Originally Posted by Salem View Post
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

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC