Page 1 of 1
How to execute shell command and read back the result in XY?
Posted: 19 Apr 2013 23:10
by avsfan
Hi,
I'm trying to figure out a way to get the current version number of a given file in my subversion repository from within XY. From the command line, I can run the following command:
which yields the result
What I want to do is to get the "274" value into a script (the value will change depending on <myfile> is used).
I looked through the scripting command reference, and nothing jumped out at me. I don't do much scripting (yet!), so please be patient!
Thanks!
Re: How to execute shell command and read back the result in
Posted: 19 Apr 2013 23:18
by 40k
You may be able to pipe the output from the command line away from stdout screen into a file.
for example:
That will dump the output from the ffmpeg help command into a file called help.txt
You can then use the readfile function to read the output into a variable.
It's a bit of a workaround but perhaps it works.
Re: How to execute shell command and read back the result in
Posted: 19 Apr 2013 23:48
by Marco
Yes, with plain command line 40k's solution is the only way.
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 06:30
by avsfan
40k wrote:You may be able to pipe the output from the command line away from stdout screen into a file.
for example:
That will dump the output from the ffmpeg help command into a file called help.txt
You can then use the readfile function to read the output into a variable.
It's a bit of a workaround but perhaps it works.
OK, so the redirect works, so that's encouraging.
So then how would I execute it and control "where" the command executes (in the current directory would be just fine), and then how do I read it back in and use the first token of that string?
Thanks!
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 06:53
by serendipity
If purpose is to read command line output then one can make use of clipboard too with "| clip".
eg:
saves two steps, creating text file and reading from text file.
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 07:11
by avsfan
serendipity wrote:If purpose is to read command line output then one can make use of clipboard too with "| clip".
eg:
saves two steps, creating text file and reading from text file.
That sounds really promising -- so how do I call that command from a script (or from the addressbar to verify)? (I feel like I should know this, but I don't!)
Thanks!
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 08:19
by highend
Code: Select all
writefile("D:\test.bat", "ipconfig | clip");
run """cmd.exe"" /c D:\test.bat", , 2, 0;
text "<clipboard>";
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 10:04
by Marco
Beware that clip:
-is not available in Win previous to 7
-clipboard may be overwritten
Source:
http://ss64.com/nt/clip.html
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 16:42
by serendipity
@Marco:Thanks for pointing that clip is a incompatible with earlier windows. I did not know that.
@avstefan: I would use 40k's method to be sure that it works on all OSs, if you are absolutely sure you'll be using Win7 or later then clip is fine. If so, something like this will work:
Code: Select all
run "ipconfig | clip";
text "<clipboard>";
Note: not all commands that work inside cmd window will work in run command line window. So try this first:
Code: Select all
run "svn list --verbose myfile";
text "<clipboard>";
If it doesn't work try highend's method.
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 17:58
by avsfan
Thanks -- I've got it working!
I just used trim(...) to get rid of the leading whitespace before using gettoken(...), and then things worked great!
I guess for Windows versions prior to 7, I could just use readfile(...) to get the data, right?
Thanks again!
Re: How to execute shell command and read back the result in
Posted: 20 Apr 2013 19:15
by serendipity
avsfan wrote:
I guess for Windows versions prior to 7, I could just use readfile(...) to get the data, right?
Yes, write to a text file and read that file. Basically, a combination of 40k's and highend's script will do the trick.