Running Visual Studio Code from the CLI in Linux - linux

I've downloaded and "installed" VSCode for Linux. I have placed the app in /home/Christian/Apps/VSCode/ and symlinked the executable to /usr/bin/code.
When I use this method to start Code it hijacks the terminal (expected I guess) and also dumps a lot of STDERR stuff at the same time.
If I redirect STDERR to a file, for example like
code 2> ~/.logs/VSCode-`date +%Y%m%d%H%M%S.log` &
Then I can get it to give me back my prompt, and it's silent (logging everything to the filename I gave it).
I was thinking of making this an alias, but then I realized I can't inject arguments ($1 $2 $3) in an alias. And I usually want to start code with code filename.js or code ..
What is the correct way to launch an application like this "in the background"?

Instead of making a symlink to the executable, create a bash script like this:
#!/bin/bash
/path/to/VSCode/Code "$#" 2>/dev/null &

Related

TextExpander, Shell Scripts, & Node

I'm trying to execute some JS code as a Node shell script, but it doesn't seem to work and I can't tell why. Here's a simple example:
#!/usr/bin/env node
console.log("foo");
The above script should result in TextExpander inserting the text "foo" when triggered, but it doesn't. The equivalent in bash works just as expected:
#!/usr/bin/env bash
echo "foo"
I thought that perhaps the call to console.log() was not producing something where TextExpander was looking (although all the documentation I can find says that should print to stdout). I've even tried a workaround like this with no luck:
#!/usr/bin/env sh
echo `/usr/bin/env node -e "console.log(\"foo\");"`
I get no visible errors or any indication that something went wrong. I just end up with TextExpander inserting an empty string instead of "foo". Any TextExpander experts out that that might see something I'm missing? Running the non-working examples in the shell work fine, and TextExpander is supposed to just capture whatever goes to stdout. I'm not even sure how I could go about debugging this.
Make sure the directory where your node executable is installed is listed in the PATH environment variable that TextExpander will use. This is probably not the same PATH value one you get in your terminal. To verify if that's the problem, try doing #!/full/path/to/node as your shebang line instead of running env. My guess is node is installed either in /usr/local/bin/node or somewhere under your home directory and neither of those are in the PATH that TextExpander has while running.
You probably should add -e to your header:
#!/usr/bin/env node -e
Or
You probably should add -e to your header:
#!/path/to/node -e

running a program in linux from perl

I want to run a program from perl by using system command(or any other ways ).
system("samtools");
I think it should pass this to shell but it complains ,Can't exec "samtools" file or directory does not exist , when I run it.I have tried many other different program for example
system("velveth");
and it works properly but not this one (samtools). Is any of you facing this problem before?
I am really puzzled.
You can give the full path to that file location.
example:
system( "/usr/bin/perl -de 1");
Try putting Linux command inside `` characters. Will work as well.
Did you modify $path for samtools in the current shell manually?
Since system starts a new sub-shell to run your command, you have to append search path for samtools yourself if doesn't exist in your .bashrc. Check it by:
perl -e 'system("echo \$PATH")'
and
echo $PATH
to see if there's any difference.

execute a gui application from the command line and send it to the background

Is there a command line utility that I can use for executing X based applications that will detach my applications from the terminal so they aren't closed if the terminal is closed?
I guess such a app could be called something like gnome-run if it existed.
I have tried dtach, but it seems that you have to provide a socket file which is a bit clunky to type. I have also tried nohup, but found that also to be a bit clunky to type by the time std out and err are redirected to /dev/null.
I guess I'm looking for a simple program that will do something similar to this:
#!/bin/bash
nohup $1 > /dev/null 2>&1 &
Yes, there is a way to do it: first you need to run your GUI app and send it to background, then you (probably) want to detach it from Bash task management. For example if I wanted to run gedit this way:
gedit &
disown %1
After that you can close your terminal window and gedit will not be killed. Enjoy!
You already wrote your program, it is called a shell script and you give it the name you like and put it somewhere. Then you either add that directory to your $PATH or in your bashrc you set:
alias gnome-run=<path>/my-awesome-script.sh
Why waste earth's resources on a program?
If you want to run an application (say, gedit) as if it was run from the GUI, use:
xdg-open /usr/share/applications/gedit.desktop
See this answer on superuser.

Execute Command-Line Command from NSIS

I'm creating my first NSI script and I'm just wondering if I can execute a command-line command from NSIS or should I just execute a batch file? I don't really know where to begin and other similar topics have gone a little over my head.
I would recommend taking a look at the nsExec plugin. I just recently had a situation where I needed to ping a server from inside an NSIS script, and the following code worked perfectly for me.
nsExec::Exec '"C:\Windows\System32\PING.EXE" $URL'
The benefit of using nsExec is that it executes the command without making a dos box pop up on your screen. The return value is pushed onto the stack, and there are a couple different ways that you can access the output of the program as well (if any exists).
There isn't a whole lot of information about the plugin on the NSIS website that I could find, but the following link should get you started in the right direction:
http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt
Edit:
I noticed you asked specifically about a COPY command which is an internal DOS command, meaning that you won't be able to execute it like I did with ping. I may be mistaken but you shouldn't need to use any outside programs to carry out basic commands like this. You should be able to replicate most of the internal commands using NSIS commands.
For Example to copy a file (or multiple files) use the NSIS command: CopyFiles
The NSIS Scripting Reference is your friend :) (So is ctrl+f)
Try using exec command http://nsis.sourceforge.net/Docs/Chapter4.html:
4.9.1.2 Exec
command
Execute the specified program and continue immediately. Note that the file specified must exist on the target system, not the compiling system. $OUTDIR is used for the working directory. The error flag is set if the process could not be launched. Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: Exec '"$INSTDIR\command.exe" parameters'. If you don't put it in quotes it will not work on Windows 9x with or without parameters.
Exec '"$INSTDIR\someprogram.exe"'
Exec '"$INSTDIR\someprogram.exe" some parameters'
We can launch a command-line command from NSIS, get the returned value and further develop the installation logic based on that.
Example: Let's say we need to get the installed clang compiler version. To get the version we have to launch:
clang --version
In NSIS we do this using ExecToStack:
nsExec::ExecToStack 'cmd /c "clang --version"'
Pop $0
Pop $0
;now we have the version in $0
Warning: Only the second Pop $0 gets the response that we want, in this case the clang version. The first Pop $0 grabs the exit code.

Bash Scripting Run from rc.local

I have made a script that uses a program called Diascope, its a video slideshow program.
I am trying to run this command in encodeVideo.sh
echo "Running diascope -clean /mnt/videos/video$1.txt..."
diascope -clean /mnt/videos/video$1.txt > /var/www/html/video/encodeVideo.log
echo "Removing old deploy dir, and making new one..."
And I am running this script from rc.local so that it runs every time I boot the instance.
All I need is to get the output of the "diascope" command, in rc.local I run encodeVideo:
/bin/bash /var/www/html/video/encodeVideo.sh > /var/www/html/video/newlog
and in newlog I can see this
Running diascope -clean /mnt/videos/video7.txt...
Removing old deploy dir, and making new one...
and /var/www/html/video/encodeVideo.log is completely empty! Diascope uses gawk, and btw I can see the output of the processing when I manually run the encodeVideo.sh script. Why can I not capture it in this log?
Is it possible that it's not standard output, so ">" doesn't actually capture it?
Any ideas would be helpful, thanks!
try redirecting stderr and stdout to filename
diascope -clean /mnt/videos/video$1.txt 1> /var/www/html/video/encodeVideo.log 2>&1
Is it possible that it's not standard output, so ">" doesn't actually capture it?
Absolutely: it could be standard error, in which case you'd have to use 2> instead of >.

Resources