windows


Is there a way to make an existing cmd window execute commands?


So here is my situtation.
I am using the Windows OS. I am running a Matlab GUI that launches another executable at startup. The other executable runs in batch mode (runs in cmd in the background).
I want to make it so when a user clicks a button on the Matlab GUI, the other executable will run a command and remain open. Is this possible?
NOTE: I do not want to open a new cmd window, I want the existing one to execute commands.
Unfortunately it does not appear that Matlab has the ability you are looking for, at least not directly. I found a post which does explain how to do it with the help of .NET though, which is fortunate since you are on the Windows platform: http://www.mathworks.com/matlabcentral/answers/72356-using-matlab-to-send-strings-to-the-stdin-of-another-console-application
I have copied a lot of this from that post
function lh = task()
% Initialize the process and its StartInfo properties.
% The sort command is a console application that
% reads and sorts text input.
process = System.Diagnostics.Process;
process.StartInfo.FileName = 'sort.exe';
process.EnableRaisingEvents = true;
process.StartInfo.CreateNoWindow = true;
% Set UseShellExecute to false for redirection.
process.StartInfo.UseShellExecute = false;
%Redirect the standard output of the sort command.
process.StartInfo.RedirectStandardOutput = true;
% Set our event handler to asynchronously read the sort output.
lh = process.addlistener('OutputDataReceived',#sortOutputHandler);
% Redirect standard input as well. This stream
% is used synchronously.
process.StartInfo.RedirectStandardInput =true;
% Start the process.
process.Start();
%Use a stream writer to synchronously write the sort input.
ProcessStreamWriter = process.StandardInput;
% Start the asynchronous read of the sort output stream.
process.BeginOutputReadLine();
%Prompt the user for 4 input text lines. Write each
%line to the redirected input stream of the sort command.
numInputLines = 0;
while(numInputLines ~= 4)
inputText = input('Enter a text line (or press the Enter key to stop):', 's');
numInputLines = numInputLines + 1;
if(~isempty(inputText))
ProcessStreamWriter.WriteLine(inputText);
end
end
disp('end of input stream');
%end the inputr stream to the sort command
ProcessStreamWriter.Close();
% wait for the sort process to write the sorted text lines
process.WaitForExit();
process.Close();
end
For handling any output from the CMD you need:
function processOutputHandler(obj,event)
%collect the sort command output and print in command window
if(~isempty(event.Data))
disp(event.Data);
end
end
You can use a stream writer to synchronously write the sort input.
processStreamWriter = process.StandardInput;
Again, I have taken this from the previously mentioned post so I can't take any credit for the code, but I do think it will be able to accomplish what you are looking for. Unfortunately, I am pretty sure this will accomplish what you need. I don't have Matlab on a Windows platform at the moment or I would test this. If you need information on using .NET code in MATLAB (its not immediately clear if you need to add some stuff to establish the .NET interface) MathWorks provides some documentation on it: http://www.mathworks.com/help/matlab/matlab_external/using-net-from-matlab-an-overview.html
Hopefully this helps, or gets you started. Let me know if there's anything else I missed.
You can approach this from the ansys side. Start it with -B-R to read a python script.
From there, you can establish some two-way protocol, for example polling files or, better, by running a web server from python.
Then you can communicate from matlab with that running instance of ansys. If you opt for a web server, you use MATLABs urlread().
Setting up a web-server with python is easy, but you have to learn how to dispatch commands to the hosting ansys application.

Related Links

Windows Batch script to redirect stdout to stdin of an EXE we've just run
Jekyll for GitHub Pages can't find rouge on Windows
Batch For Loop Treating Space-delineated Input as Single Token
What is the reason for the CD /D switch in Windows cmd?
install natlink and dragonfly for python2.7 in windows10
python setup.py install - fails with error 5: permission denied
Are there Powershell cmdlets that install and remove Windows drivers?
Does FindWindow work in FMX?
How can i draw to or add a custom button to every window of all applications?
How do I get my Windows7 symlink to execute from command line?
Searching static data using Windows Search Service with IIS
How to sync Time with NTP server on windows
Assembly reference issue when using shared project from iOS and Android Xamarin projects
Changing the image on a button when clicked xaml
Windows Explorer start notification
Is it possible to reinstall winodows with same key came with the machine [closed]

Categories

HOME
beautifulsoup
api
gdb
polymer
github-for-windows
yahoo-finance
requirements
telegram-bot
trac
opengl-3
accessibility
okhttp
pattern-matching
fabric.io
endeca
fhir
tput
speech-synthesis
plink
null-pointer
standards
chargify
fileserver
forgot-password
google-maps-autocomplete
rubymotion
jquery-ias
dpdk
roslyn
xcode-ui-testing
stackexchange
ms-access-web-app
handler
iis-express
jaws
sqsh
constexpr
memory-address
papaparse
login-script
hibernate-search
numpy-broadcasting
apiary.io
sql-server-ce
z-notation
recurrent-neural-network
demo
setup.py
odoo-website
postgresql-8.4
puredata
user-defined-fields
gpg-signature
cmp
rxtx
taocp
ziparchive
spreadjs
phpgrid
crouton-os
decimalformat
zen-cart
sha512
pyobjc
public-html
ejb-2.x
administration
formview
ss7
koala
drupal-nodes
sphinxql
windows-phone-8-sdk
superscrollorama
mysql-error-2013
apache-abdera
android-sdk-2.3
sqlclr
dopostback
frameworkelementfactory
patricia-trie
nokia-s40
pyunit
koken
procedures
lr
tournament
aspmenu
django-piston
cardspace

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile