0

Basically I am trying to open an application (mingwenv.cmd) and run a command in it

/c/Users/jab/src/veins-4.4/sumo-launchd.py -vv -c /c/Users/jab/src/sumo-0.25.0/bin/sumo-gui.exe

via Batch scripting, analogous to opening, say, python.exe in a new command prompt and running

python -m pip install xlutils

on the command line interface in the new command prompt. I've spent several hours trying to do so, to no avail.

Below are my documented attempts:

sthcmd C:\Users\jab\src\SUMO_OMNeT_connection.txt | C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd           
cmd /k & sthcmd C:\Users\jab\src\SUMO_OMNeT_connection.txt | C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd  
C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd | C:\Users\jab\src\SUMO_OMNeT_connection.txt                  
C:\Users\jab\src\SUMO_OMNeT_connection.txt|C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd                    
C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd < C:\Users\jab\src\SUMO_OMNeT_connection.txt                  
type C:\Users\jab\src\SUMO_OMNeT_connection.txt | C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd             
type C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd | C:\Users\jab\src\SUMO_OMNeT_connection.txt             
echo /c/Users/jab/src/veins-4.4/sumo-launchd.py -vv -c /c/Users/jab/src/sumo-0.25.0/bin/sumo-gui.exe | C:\Users\jab\src\omnetpp-5.0\mingenv.cmd            
echo "/c/Users/jab/src/veins-4.4/sumo-launchd.py -vv -c /c/Users/jab/src/sumo-0.25.0/bin/sumo-gui.exe" | C:\Users\jab\src\omnetpp-5.0\mingenv.cmd          
start C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd /k /wait "/c/Users/jab/src/veins-4.4/sumo-launchd.py -vv -c /c/Users/jab/src/sumo-0.25.0/bin/sumo-gui.exe" 
C:\Users\jab\src\omnetpp-5.0\mingwenv.cmd "/c/Users/jab/src/veins-4.4/sumo-launchd.py -vv -c /c/Users/jab/src/sumo-0.25.0/bin/sumo-gui.exe" 

preceding the code block but only the last one worked and the highlighting was vastly off) perhaps someone knows how to do that, if it's possible. In the meantime the code block can be copied into Notepad++ and highlighted there. Anyways, here are the results and references per attempt(s):

  1. crashes (nothing happens) (https://www.codeproject.com/Questions/747981/send-command-to-another-program-with-batch-file)
  2. basically just prints the command to the cmd prompt, seems to expect other commands
  3. opens cmd, txt file, and mingwenv.cmd prompt (3 windows) separately
  4. opens cmd, txt file, and mingwenv.cmd prompt (3 windows) separately
  5. just opens mingwenv.cmd; all else crashes (How to make a batch file that send application an input char)
  6. just opens mingwenv.cmd and cmd prompt only (not txt file) (How do I send commands to an EXE running through the command line with batch?)
  7. just opens txt and cmd prompt only (not mingwenv.cmd)
  8. does nothing (crashes) (How to make a batch file that send application an input char)
  9. does nothing (crashes)
  10. opens mingwenv.cmd and cmd prmpt stays open, that's it though (Bat file to run a .exe at the command prompt)
  11. opens mingwenv.cmd, cmd prompt crashes (BAT file: Open new cmd window and enter code in there)
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • That depends. What does `mingwenv.cmd` actually do? From Googling, it *looks* as if it just runs a Windows command shell with the MinGW environment set up, but you seem to be trying to run a UNIX-like command. – Harry Johnston Sep 29 '17 at 02:57
  • ... anyway, since it is just a batch script, it might be wise to look at it and see what it is actually doing. If it finishes by running a bash-like executable, that executable probably has command-line options that might be what you're looking for. – Harry Johnston Sep 29 '17 at 03:01
  • It would be usefull if you post the content of the batch file. running a batch file with parameters will not work if the batch is not setup to capture these parameters. – Gerhard Sep 29 '17 at 05:53
  • The syntax highlighting should be `` –  Sep 29 '17 at 13:11
  • @SteveFest Thanks for the edits - very clarifying, though the syntax highlights don't seem to be assigned properly (i.e. the commands echo, type, start are usually bold and colored in a programming editor) Gerhard Barnard: Each attempt contains the entire contents of the batch file (each line is a separate attempt). Harry Johnston: Overall My goal is to pass the entire command as a string to the new command prompt and then run it (i.e. equivalent to opening a specific application, like a python shell, copying/pasting the command from a text editor to a command prompt and then pressing Enter) – Jeremiah Blackburn Sep 29 '17 at 14:45
  • @JeremiahBlackburn It is because the Google highlighter doesn't support Batch as a scripting language. It supports major ones like C, Java, CSS, HTML.... –  Sep 29 '17 at 23:35
  • I think Gerhard meant the batch file that you're calling, i.e., `mingwenv.cmd`. But since it is part of a third-party product, probably covered by the GPL, posting it here [would be legally risky at best](https://meta.stackoverflow.com/questions/287986/posting-gpl-code-in-an-answer). If you can find a copy of it already online (that is the same as yours) you might give us a link to that. – Harry Johnston Sep 29 '17 at 23:43
  • So, your latest comment suggests that `mingwenv.cmd` opens a brand new console window. There's no way (in batch) to pipe to or redirect stdio for a new window, so the only variants that could possibly work are #10 and #11, and they'll only work if `mingwenv.cmd` actually accepts parameters. You should be able to tell whether or not it does by examining the source code. – Harry Johnston Sep 29 '17 at 23:48
  • Thank you Harry Johnston and SteveFest; I wasn't aware of those limitations. The code is open-source so I think it's okay; here're somewhat relevant links: (https://omnetpp.org/intro/license), (https://omnetpp.org/), (https://omnetpp.org/pmwiki/index.php?n=Main.MingwInstallationDetails), (https://www.packtpub.com/mapt/book/application_development/9781849697149/2/ch02lvl1sec14/downloading-omnet---source-code). Please let me know what you all think; thank you for all of your considerations thus far. – Jeremiah Blackburn Oct 01 '17 at 14:32
  • According to [this](http://www.mingw.org/license) MinGW itself is MIT licensed, which is also [the default for SO](https://meta.stackexchange.com/q/271080/187745) so I guess that's OK. IANAL. – Harry Johnston Oct 01 '17 at 21:51
  • Sounds good; thank you. I'll suppose then that in general it is not as straightforward to open a third party application and then run a command in that third party application via Batch scripts without accessing the third party application's source code. I'll just open the third party application with Batch and keep the commands in a text file and copy/paste them. Thank you all though for your efforts. – Jeremiah Blackburn Oct 02 '17 at 16:13

0 Answers0