output_from() function - specman

i'm new to specman.
how do i use the output_from() function. and what does it do?

6.1.1 docs say:
25.8.4 output_from()
Purpose:
Collect the results of a system call
Category
Routine
Syntax :
output_from(command: string): list of string
Syntax Example
log_list = output_from("ls *log");
Parameter
command
A single operating system command, with or without parameters and enclosed in double quotes.
Description:
Executes the string as an operating system command and returns the output as a list of string. Under UNIX, stdout and stderr go to the string list.
Example
<'
extend sys {
m1() is {
var log_list: list of string;
log_list = output_from("ls *log");
print log_list;
};
};
'>

Related

Two PowerShell methods: SetString() accept a string from the user and PrintString() print the string in upper case

What can I do so that I write the desired phrase in brackets and it will be accepted?
Where exactly to get the "basis" in order to make a return using the "PrintString" method?
# Example 1
$Object.SetString("gamarjoba")
# Example 2
$Object.PrintString()
# Returns
GAMARJOBA
Here is one of my attempts:
class Object {
[string]$gamarjoba
[string]SetString() {
return Write-Host "gamarjoba"
}
[string]PrintString() {
return Write-Host "gamarjoba".ToUpper()
}
}
I understand that this is a very basic question, but I have already spent too much time on it.
You're probably looking for this:
class MyObject {
[string] $gamarjoba = '' # instance variable
# Method has no return type; accepts a string parameter
# and assigns it to instance variable $this.gamarjoba
[void] SetString([string] $gamarjoba) {
$this.gamarjoba = $gamarjoba
}
# Returns the uppercased form of the $this.gamarjoba instance variable.
# Do NOT use Write-Host.
[string] PrintString() {
return $this.gamarjoba.ToUpper()
}
}
$obj = [MyObject]::new() # create an instance
$obj.SetString('aha') # set the string
$obj.PrintString() # print the uppercased string
Note that I've named the class MyObject, because Object would clash with the root class of the .NET type hierarchy.
As for what you tried:
return Write-Host "gamarjoba".ToUpper()
Fundamentally, do NOT use Write-Host to return or output data - it is meant for printing information to the display (console), and bypasses the success output stream and thereby the ability to send output to other commands, capture it in a variable, or redirect it to a file - see this answer for more information.
In the context of class definitions, use only return to return data from a method, passing it an expression or command as-is (e.g, return 'foo'.ToUpper() or return Get-Date -Format yyy)
PowerShell classes participate in the system of output streams only in a very limited way:
returning a value from a method writes it to the success output stream.
Notably, implicit output and use of Write-Output (i.e. what you would use in a script or function) are not supported and quietly ignored. (While you can use return Write-Output ..., there's no good reason to do so.)
throwing an error writes it to the error stream - but you'll only see that if you catch or silence such a fatal-by-default error.
Notably, using Write-Error to write non-terminating errors does not work and is quietly ignored.
However, you can write to all other output streams using their respective Write-* cmdlets, such as Write-Warning.

Powershell parsing of a C# file to get values of constants

I need to parse some C# files to get the values of some constant variables. I know I can do something like
$input = Get-Content C:\somefile.cs ...
then loop over each line and do some text matching.
...but was wondering whether I can utilize some sort of a C# DOM object to get the values of constants?
You can load the type dynamically from the powershell command line, and then evaluate the constant.
Example:
C:\somefile.cs contents:
public static class Foo
{
public const string SOME_CONSTANT = "StackOverflow";
}
Powershell command line:
Add-Type -Path C:\somefile.cs
$constantValue = [Foo]::SOME_CONSTANT

Add method to string class in node.js express.js coffeescript

I want to add some my methods to generic types like string, int etc. in express.js (coffeescript). I am completely new in node. I want to do just this:
"Hi all !".permalink().myMethod(some).myMethod2();
5.doSomething();
variable.doSomethingElse();
How to do this ?
You can add a method to the String prototype with:
String::permaLink = ->
"http://somebaseurl/archive/#{#}"
String::permalink is shorthand for String.prototype.permaLink
You can then do:
somePermalink = "some-post".permaLink()
console.log somePermalink.toUpperCase()
This will call the the "String.prototype.permaLink" function with "this" set to the "some-post" string. The permaLink function then creates a new string, with the string value of "this" (# in Coffeescript) included at the end. Coffeescript automatically returns the value of the last expression in a function, so the return value of permaLink is the newly created string.
You can then execute any other methods on the string, including others you have defined yourself using the technique above. In this example I call toUpperCase, a built-in String method.
You can use prototype to extend String or int object with new functions
String.prototype.myfunc= function () {
return this.replace(/^\s+|\s+$/g, "");
};
var mystring = " hello, world ";
mystring.myfunc();
'hello, world'

Perl method fails when I use a variable as opposed to a string literal

Getting some odd behaviour in a Perl script that I don't quite understand. I'm trying to make some of my magic string literals into variables that can be modified more easily.
I have an argument in my subprocedure called $in_feature. Right now it's value is simply "in_feature". I can print it out and it looks fine. So far so good...
This code fails, though:
if ($in_feature != "" && !$blockModel->is_field($in_feature))
{
print "ERROR: was expecting to find a variable in the block model called $in_feature.\n";
return;
}
If I remove the string comparison and change the method call back to the string literal it works as expected.
if (!$blockModel->is_field("in_feature"))
{
print "ERROR: was expecting to find a variable in the block model called $in_feature.\n";
return;
}
So the variable is somehow a string, that is equal to empty string, and can't be used in place of a string?!? Why's this?
String comparison in perl uses ne and eq instead of != and ==
Replace $in_feature != "" with $in_feature ne "" and it might fix your issues.

Is it possible with Eclipse to only find results in string literals?

Lets assume I have the following Java code:
public String foo()
{
// returns foo()
String log = "foo() : Logging something!"
return log;
}
Can I search in Eclipse for foo() occurring only in a String literal, but not anywhere else in the code? So in the example here Eclipse should only find the third occurrance of foo(), not the first one, which is a function name and not the second one, which is a comment.
Edit: Simple Regular Expressions won't work, because they will find foo() in a line like
String temp = "literal" + foo() + "another literal"
But here foo() is a function name and not a String literal.
You can try it like this:
"[^"\n]*foo\\(\\)[^"\n]*"
You have to escape brackets, plus this regex do not match new lines or additional quotes, which prevent wrong matches.
Maybe you should use regex to find any occurence of foo() between two " ?