I'm creating a GUI for a terminal command. To achieve this, I am using the following:
let task = Process.launchedProcess(launchPath: path, arguments: arguments)
where path is the path of the executable, and arguments is my arguments array variable.
When this task is run in the GUI, text is output to Xcode's console, akin to what you see when you run the command in the terminal. I'd like to display this text (or the terminal output) in a Scroll View in my application. However, I can't figure out how to do that.
Related
I see this unnecessary file path information whenever I execute a program in the terminal section.
Is there a way to hide that file path?
This is not so much VSCode terminal related, rather it is more shell related (see What's the difference between Terminal, Console, Shell, and Command Line). Your VScode's terminal is running a shell internally, but a terminal is not much more than a display window that calls a shell's functions. So, in order to edit the prompt (which comes from the shell), we have to edit your shell config.
From your screenshot, it looks like the particular shell you're running is Powershell. Powershell has its own prompt that it generates each time before you run a command. It does so by calling the prompt() function (you can read more about it at Microsoft Docs).
Therefore, if you just want an empty prompt, then all you have to do is create an empty prompt function and add it to your powershell profile.
From your terminal, open your powershell profile file using VSCode (or any text editor)
# $profile is a variable in powershell
# that holds path of the powershell config
code $profile
Then add an empty prompt function into the profile
function prompt { }
Save the file and reopen another powershell instance in your VSCode terminal, and now it should look like this
PS>
If you're interested in further customizing this prompt, I would highly recommend looking into starship, a cross-platform shell prompt that can be used inside powershell. By default it's an even simpler arrow
❯
It only displays the most relevant paths, and can be customized to a much greater extent than the powershell prompt.
When I run a terminal command it generates some text data in the terminal display. Suppose blck is some executable software tool installed on my desktop. I call this tool in the terminal on a file named main.txt in the current working directiory like this:-
$ blck -f main.txt
This prints some information immediately below the command call. I have to process this text to glean some information from it. I have the matlab code to process this text. But how to call this terminal command in Matlab and then transfer the resulting text information to Matlab variables. once I have the information displayed from the command call in Matlab then I can simply run my processing code on it.
I need a the electron start with transparent window in linux, the documents say I need put --enable-transparent-visuals --disable-gpu in the command line. Is there a way to pass the command line args in the program not in the terminal command line.
like this:
electron . --enable-transparent-visuals --disable-gpu
I need when I run
electron .
the args have set in the program.It means I just double click the bin file and the args are OK. Don't need to pass them manually.
You can put them in the main script of the application (main.js), before the 'ready' event of the app module is emitted, like so:
const electron = require('electron')
// Module to control application life.
const app = electron.app
app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');
app.on('ready', () => {
// Your code here
});
For a list of other command line switches, you can go here
I have a executable that when double clicked opens in a command line window.
Now there is a input file (i.e named "sphere_15000.inp") in the same directory where the executable apame_win64.exe is located. So we can inter the file name in the command line.
The question is how this can be done from mathematica front end? With the RunThrough command I tried to do it with no avail.
RunThrough["Executable Location", "sphere_15000"]
Do I need to put this file location in my Windows 7 environment path variable? Hope for some suggestion in this regard.
UPDATE
Found a solution to my problem.
First set the Mathematica directory to the folder where the executable is located.
path="C:\Users\FlowCrusher\Desktop\CUSP solver\Apame_build_2011_01_09\solver";
SetDirectory[path];
Then use the following style of input.
Run["\"\"apame_win64.exe\" \"input\"\""]
Here "apame_win64.exe" is the executable one want to run and "input" is the input file for the executable. This solves the problem. But a new item in the wishlist.
Is there a way to hide the console window in the background?
Here is how it looks on my screen.
As Chris suggested if we use minimized console in the Run command we get a minimized window but the program does not execute.
I hope that a solution exists.
BR
Yes, you might put the folder of you executable into the Path variable, or provide the full path name.
However, RunThrough seems to have been superseeded (on Windows) by
Import["!command ","Text"], which will execute command and read the comaand line output into Matheamtica as a string.
E.g.:
Export["testit.txt", "bla", "Text"];
Import["!dir" <> " testit* > dir.log", "Text"];
FilePrint["dir.log"]
--
Otherwise, I also had good results in the past using NETLink (not sure if WScript.shell
still works on Windows7/8 or if one should use something else).
Emulating Run (RunThrough is not really needed I think):
Run2[cmd_String] := Module[{shell},
Switch[$OperatingSystem,
"Windows",
Needs["NETLink`"];
shell = NETLink`CreateCOMObject["WScript.shell"];
shell # run[cmd,0,True],
"Unix",
Run # cmd,
"MacOSX",
Run # cmd ] ];
Can you run your application with input from a basic command window instead of the application console? This might be the form of command you would need:
apame_win64 -input sphere_15000.inp
or simply
apame_win64 sphere_15000.inp
You can probably check the available switches by running apame_win64 -help
A multi-part command can be run from Mathematica, e.g.
Run["type c:\\temp\\test.txt"]
Alternatively, also returning output to the Mathematica session:
ReadList["!type c:\\temp\\test.txt", String]
I landed here wanting to run abaqus command line on windows.
The solutions provided here worked out for me (Windows 7, Mathematica 9):
SetDirectory#path;
Run["start /min abaqus job=" <> fileName <> " interactive ask_delete=OFF >> log.txt"]
(Here the abaqus option ask_delete=OFF overwrites an existing simulation results and the >> redirects all the output to a file)
I think, minimizing the window did not run in your case since the executable throws open that window. In that case, this might be of some help
On my PC, VBS files are set (via the file association entries in the registry) to run using WScript. This is what I want, so that I can double click on a VBS file and not have a console window open. However, when I am using the Powershell command line, I would like VBS scripts to run using CScript (i.e., using "cscript /nologo myfile.vbs"). Is there a way to make Powershell do this, without affecting the double-click behaviour?
For single scripts, I could write a function for each one (function foo { cscript /nologo foo.vbs $args }) but that doesn't scale at all. I'm thinking of something like Take Command's "executable extensions" feature, that lets you set a specific action for a file extension (set .vbs=cscript /nologo).
I have the same problem for Python scripts, where again the default action doesn't do what I want (for some reason, it opens a second console window, rather than displaying output in the Powershell console) so a VBS-specific answer will only give me part of what I want :-(
Thanks,
Paul
The easiest thing i can think of is, to set an environment variable whenever you start Power Shell (does it have an autoexec feature?) let's call it "InPowerShell" and give it the value "YES".
Then create a .bat file like this:
if %InPowerShell%==YES (
cscript /nologo #*
) else (
wscript #*
)
Set all vbs files to open with this bat file. This way whenever you double click it it will be opened with wscript, and inside powershell will open with cscript.
(Note: I didn't test this)