Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass switches to Runtime.getRuntime().exec

Status
Not open for further replies.

Wrathchild

Technical User
Aug 24, 2001
303
US
Hi, my application opens other applications and files by using the Runtime.getRuntime().exec command. Everything is working fine; now I'm trying to pass a switch for further functionality.
Example:
I'd like to pass the switch "/t" to an Outlook command to open a template. Currently, without the switch, the template is being embedded within a new email. I've tried many different ways to do this and looked around the net but have been unsuccessful.
Below is the error I keep receiving:
CreateProcess: "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE /t " "\My Folder\IT Mgt Approval.oft" error=3


Code:
	private static Map myMap = new HashMap();
	static {
		// store application paths
		myMap.put(new Integer(7),
				"C:\\Program Files\\Microsoft Office\\OFFICE11\\OUTLOOK.EXE");
	}
Code:
{
							commands = new String[] {
									(String) myMap.get(new Integer(
											theMenuConfig.getId())),
									theMenuConfig.getPath() };
						}
						Process child = Runtime.getRuntime().exec(commands);
					}

thanks!
 
thanks stefan - I was trying that, but syntax was also an issue

here's the solution:

Code:
else if (
							theMenuConfig.getId() == 7) {
							//handle for email templates; pass switch "/t" so template isn't embedded in new email
							commands =
								new String[] {
									(String) myMap.get(
										new Integer(theMenuConfig.getId())),
									"/t",
									theMenuConfig.getPath()};

I also needed to use quotes around the application path and the file path; the final results s/b "App path",/t,"File path" passed to be executed
Use escape characters around application path:
Code:
		myMap.put(
			new Integer(7),
			"\"C:\\Program Files\\Microsoft Office\\OFFICE11\\OUTLOOK.EXE\"");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top