From 7f05ace5bd8dd57cad510bd07683b0b3f57cfaf1 Mon Sep 17 00:00:00 2001 From: David McKnight Date: Wed, 26 Apr 2006 20:42:02 +0000 Subject: [PATCH] fix for remote windows shell --- .../miners/command/CommandMinerThread.java | 39 +++++++++++++++---- .../miners/environment/EnvironmentMiner.java | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java index 2a2acdd1ca3..05841f01d96 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/command/CommandMinerThread.java @@ -292,8 +292,19 @@ public class CommandMinerThread extends MinerThread args[1] = "/C "; } args[2] = _invocation; - _theProcess = Runtime.getRuntime().exec(args, getEnvironment(_subject), theDirectory); - System.out.println("started shell:"+args[0] + " " + args[1] + " " + args[2]); + System.out.println("getting env..."); + String[] env = getEnvironment(_subject); + System.out.println("...got env"); + if (_invocation.equals(theShell)) + { + + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } + else + { + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + } @@ -555,7 +566,7 @@ public class CommandMinerThread extends MinerThread writer.flush(); - if (input.startsWith("cd ") || input.equals("cd")) + if (!_isWindows && (input.startsWith("cd ") || input.equals("cd"))) { queryCWD(); } @@ -612,12 +623,15 @@ public class CommandMinerThread extends MinerThread DataElement projectEnv = null; if (projectEnvReference != null && (projectEnvReference.size() > 0)) projectEnv = (DataElement) projectEnvReference.get(0); + + String[] theEnv = mergeEnvironments(systemEnv, projectEnv); return theEnv; } private String[] mergeEnvironments(DataElement systemEnv, DataElement projectEnv) { + List prjVars = null; List sysVars = null; //Fill the ArrayLists with the environment variables @@ -633,8 +647,10 @@ public class CommandMinerThread extends MinerThread //If we get here, then we have both system and project variables...to make merging the 2 lists easier, we'll //use a Hashtable (Variable Names are the keys, Variables Values are the values): Hashtable varTable = new Hashtable(); + //First fill the varTable with the sysVars varTable.putAll(mapVars(sysVars)); + //Now for every project variable, check to see if it already exists, and if the value contains other variables: for (int i = 0; i < prjVars.size(); i++) { @@ -648,12 +664,14 @@ public class CommandMinerThread extends MinerThread varTable.put(theKey, theValue); } - + if (_isTTY) { varTable.put("PS1","$PWD/>"); varTable.put("COLUMNS","256"); } + + /* DKM: for some reason this isn't getting applied properly here * but it works via export * */ @@ -700,7 +718,7 @@ public class CommandMinerThread extends MinerThread } } //If the current char is a $, then look for a { or just match alphanumerics - else if (c == '$') + else if (c == '$' && !_isWindows) { int nextIndex = index + 1; if (nextIndex < theValue.length()) @@ -721,9 +739,14 @@ public class CommandMinerThread extends MinerThread { if (Character.isJavaIdentifierStart(c)) { - while ((nextIndex < theValue.length()) && (Character.isJavaIdentifierPart(c))) - c = theValue.charAt(++nextIndex); - String replacementValue = findValue(theValue.substring(index + 1, nextIndex), theTable, true); + while (nextIndex + 1 < theValue.length() && (Character.isJavaIdentifierPart(c))) + { + nextIndex++; + c = theValue.charAt(nextIndex); + } + + String v = theValue.substring(index + 1, nextIndex); + String replacementValue = findValue(v, theTable, true); theValue.replace(index, nextIndex, replacementValue); index += replacementValue.length() - 1; } diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java index 4596b6cf029..d8a03c7293a 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/dstore/universal/miners/environment/EnvironmentMiner.java @@ -155,7 +155,7 @@ public class EnvironmentMiner extends Miner String theOS = System.getProperty("os.name").toLowerCase(); //If we're on windows, change the envCommand. if (theOS.startsWith("win")) - envCommand = "cmd /c set"; + envCommand = "cmd /C set"; if (theOS.startsWith("os/400")) {