Author Topic: Problems with _PipeShellResult and _PipeProcess  (Read 2787 times)

radensb

  • Community Member
  • Posts: 5
  • Hero Points: 0
Problems with _PipeShellResult and _PipeProcess
« on: May 30, 2013, 05:37:01 pm »
I have read the thread:
http://community.slickedit.com/index.php?topic=2799.0
and the documentation for _PipeShellResult, which states in the Example Section:
"_PipeShellResult("cd", status) returns the current working directory as reported by the operating system shell."

BUT IT DOESENT!  :o
_PipeShellResult("cd", status) always returns an empty string and status of -2.
_PipeShellResult("test.bat", status) returns the current working directory when test.bat contains:
@echo off
cd


The trick to use a .bat file works! I am creating commands for the command line programmatically, so using the .bat file is not a viable option. Based on the documentation and the example in the documentation, I should be able to pass commands directly as strings and have them executed. I used the debugger and found that _PipeProcess (which is in the _PipeShellResult() function) returns a code of -2 if the cmdline argument is the command itself (like "cd" or "dir") which results in the function returning an empty string. I cannot debug into that function because it is an extern and slickedit cannot find the source code.

Whats the deal here? Anyone else have this problem? Im currently using v15 (2010) but may be upgrading to v17 (2012) soon.

One of the applications I am using this for is to populate a dropdown list with parsed information from the console output. It works great with the bat file, however, flexibility is very limited and I need to be able to use the function as it is documented to work.

Thanks for the help!

-Ryan

radensb

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Problems with _PipeShellResult and _PipeProcess
« Reply #1 on: June 03, 2013, 04:26:45 pm »
 ???
Really? No one has noticed this or has a solution?

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Problems with _PipeShellResult and _PipeProcess
« Reply #2 on: June 03, 2013, 04:42:02 pm »
I would expect you'd need to use _PipeShellResult("cmd /c cd", status).

"cd" isn't a program or script, it's an internal command inside cmd.exe that only cmd.exe knows how to handle.  But test.bat is a script and the .bat extension indicates that in order to run the script cmd.exe must be invoked, which is how it knows to invoke cmd.exe in that case.

radensb

  • Community Member
  • Posts: 5
  • Hero Points: 0
[SOLVED]Re: Problems with _PipeShellResult and _PipeProcess
« Reply #3 on: June 03, 2013, 05:40:42 pm »
FIGURED IT OUT!

Here is the documentation from slickedit:
Quote

_str _PipeShellResult(_str cmdline, int &status, _str options="")
 Execute cmdline and return output from stdout.
 IMPORTANT: If the process never exits, then you will have to break the Slick-C® macro (Ctrl+Alt+Shift+F2).
 Note:
Only stdout is read. If the process only outputs on stderr, you will get an empty string back.
Parameters:
cmdline - Command line to execute.
status - Status/exit code of shelled process.
options - (optional). Options are: 'A' = Asynchronous (do not wait for execution to complete). 'C' = Execute in a console window. 'H' = Hide application window. Defaults to "".
Returns: _str
_str output from stdout of shelled process.
Example:
_PipeShellResult("cd", status) returns the current working directory as reported by the operating system shell.

It seems that this is incorrect as the example clearly shows passing a command string ('cd' in this case) and having it execute. The comment from chrisant lead me in the correct direction. It seems that environmental variables are not used, so everything needs to be defined.

The following:
Code: [Select]
_str result = _PipeShellResult("cmd /c cd", status);
or
_str result = _PipeShellResult("cmd.exe /c cd", status);
did not work. I got the same result as before with an empty string being returned.

HOWEVER...
Code: [Select]
chdir("C:\\WINDOWS\\system32");
_str result = _PipeShellResult("cmd.exe /c cd", status);
did work! You have to tell it where cmd.exe is. The above goes to the directory that contains cmd.exe and executes it with the command.

So this is what I am using now:
Code: [Select]
int status = 0;
_str cmdStr = get_env("ComSpec") :+ " /c " :+ cmd;
_str result = _PipeShellResult(cmdStr, status);
where 'ComSpec' is the environment variable for cmd.exe. (get_env() returns the path C:\WINDOWS\system32\cmd.exe), and 'cmd' is the command that I want to execute.

So finally, it is working as expected. But the documentation for _PipeShellResult needs to be updated or the function modified to operate "as advertised"...