ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Drag&Drop Robot

Suggestion: Use Comspec

<< < (2/5) > >>

myarmor:
But just to clarify i'm understanding things.. if you manually change your commandline item to start with "c:\program files\jpsoft\tcmd9\tcc.exe" then does it do what you want?  OR are you saying that this issue only comes up when D+DR is auto-creating .bat files and launching them (which happens when D+DR sees a commandline that doesnt start with a .exe).
-mouser (June 06, 2008, 03:01 PM)
--- End quote ---

The above seems like a too complicated way to do things..
Yes, cmd.exe is ran when creating temporary batch files too..

This is what happens when running a .bat file:
-- Log from Outpost Firewall --
23:48:20   Command line: cmd /c "D:\tmp\test.bat"
23:48:20   Process CMD.EXE started by draganddroprobot.exe
-----------------------------

The "cmd" part of the line above is what I'd like to have changed with the content of the comspec environment variable.
The issue is caused by anything starting "cmd" instead of the designated command processor.

The point is, instead of executing cmd /c "D:\tmp\test.bat" in the example above you would execute "%comspec%" /c "D:\tmp\test.bat".
Comspec in the preceding sentence is still the expanded contents of that variable.

- Take command understands batchfiles perfectly, but cmd doesn't understand the tcc extensions to the language.
  you can detect inside a batchfile if it runs under the normal command processor or tcc.
- Using the .btm extension would be option, but would result in D+DR first executing cmd, then tcc, for every single file.
- Starting all commandlines with c:\program files\jpsoft\tcmd9\tcc.exe /c might also work, but makes it less flexible
to change (such as tcc changing path, or the configuration and batchfile is delivered to someone without Take command) than just
the straight forward d:\tmp\test.bat .

Another way to support this, if you want to do it the hard way, is to support this type of command typed into the D+DR commandline:
%VARIABLENAME% parameters or, taken a bit longer
%SYSTEMROOT%\notepad.exe "%HOMEDRIVE%\%HOMEPATH%\test.txt"

It might even be more powerful.
D+DR would then simply expand the variable(s) provided before interpreting it, then execute.

This way it would still remain flexible, in which you can write %COMSPEC% /c d:\tmp\test.bat, essensially doing the same as I wish for.

But this was just a small suggestion..


@f0dder, Most likely a CreateProcess or ShellExecute of cmd.exe

mouser:
The reason that there is a bit of confusion and probably what f0dder is getting at, is the fact that i dont ever call cmd.exe explicitly.

I actually dont use shellexecute either, i usee CreateProcess because it allows me to pipe the output and capture it to be displayed in the program.

So the point is that the OS is the one deciding to launch cmd.exe to execute the .bat files.  Which is i think why f0dder was suggesting that maybe there are other places where you should configure the OS to tell windows to always launch .bat files with tcc.exe.

I could however try to either check the environment and try to launch bat files with replacement COMSPEC or allow an option of how .bat files should be launched explicitly rather than relying on OS to decide which program to use.

Question: Would you ONLY use %COMSPEC% for launching .bat files? or would you use it for ALL shelling of any executable?

myarmor:
The reason that there is a bit of confusion and probably what f0dder is getting at, is the fact that i dont ever call cmd.exe explicitly.

I actually dont use shellexecute either, i usee CreateProcess because it allows me to pipe the output and capture it to be displayed in the program.

So the point is that the OS is the one deciding to launch cmd.exe to execute the .bat files.  Which is i think why f0dder was suggesting that maybe there are other places where you should configure the OS to tell windows to always launch .bat files with tcc.exe.

I could however try to either check the environment and try to launch bat files with replacement COMSPEC or allow an option of how .bat files should be launched explicitly rather than relying on OS to decide which program to use.

Question: Would you ONLY use %COMSPEC% for launching .bat files? or would you use it for ALL shelling of any executable?
-mouser (June 06, 2008, 05:56 PM)
--- End quote ---

Please reread the my previous message, I edited it a bit..

the expanded %comspec% would be used wherever cmd would, or the alternative, should you decide on that would
also do just fine.

mouser:
Just to reiterate in case there is still some confusion.  it's not a matter of me using %COMSPEC% in place of cmd.  because i never use "cmd".  The OS chooses to use cmd and the OS invokes it when i call CreateProcess.

So the solution cannot be to use %comspec% in pace of cmd in my code.  The solution could be to modify the commandline given to CreateProcess and to manually override the OS choice of command processor by explicitly passing something like CreateProcess("%COMSPEC% NORMAL_COMMANDLINE_HERE") instead of the normal CreateProcess("NORMAL_COMMANDLINE_HERE").  If that works without issue then it's a reasonable solution.  I just have to see if that works ok and doesn't break io redirection piping.

f0dder:
I've just done some testing, and it seems that CreateProcess does not respect %ComSpec%. I started a shell, set ComSpec to something silly (zoomin.exe, it has a GUI so it definitely shows up if used) - if I then launch a .bat file (with the "start" command, just typing x.bat doesn't use the (new) ComSpec but the existing cmd.exe instance), sure enough, zoomin starts up.

I then made a little test app that MessageBox()'es it's commandline as well as %ComSpec%, then launched x.bat. Sure enough, %ComSpec% was inherited correctly, but still cmd.exe was launched - so CreateProcess definitely doesn't use it (haven't changed my .bat registry association, so dunno if it was looked up there).

ShellExecute doesn't use %ComSpec% either. Also, I made the batch file print %ComSpec%, and both with CreateProcess and ShellExecute, c:\usr\bin\zoomin.exe was printed, as expected.

So really, this is no fault of mouser's :) - pretty annoying anyway, as it sounds like .cmd and .bat need special manual handling in order to use %ComSpec%...

EDIT: mouser, you should only do this %ComSpec% thing explicitly for batch files, I doubt console apps launched through a command interpreter will pipe correctly - or at least that there could be issues with it.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version