specman issue with parsing quotation marks - specman

I am trying to import a string from the unix shell to the program space of specman.
The string i want to import contains quotation marks ("") - for example "hi".
in these cases, the string is not parsed properly . for example
suppose i want to 'echo' some string with quotation marks, i would do the following:
%> echo echo \"\"hi\"\"
will output
""hi""
but if i use the following program, written in e:
<'
extend sys {
run() is also{
print output_from("echo \"\"hi\"\"");
stop_run();
};
};
'>
i get the following output:
output_from("echo \"\"hi\"\"") =
0. "hi"
as you can see - quotation marks are gone. the ones that we see here are coming from the default printing of list values.

I'm not familiar with the output_from action, but I assume it treats the input string as a shell command.
By writing "echo \"\"hi\"\"" what you will essentially get is a string containing echo ""hi"". This is because the \ will be "eaten up" (it's an escape character in e as well). The resulting string is what will be executed, which if you try in the shell will also output the same thing. Try adding an escaped \ as well. I don't have the possibility to start Specman anytime soon so you'll have to try it out.
To test my hypothesis:
// just to see what happens with your original string
var some_string : string = "echo \"\"hi\"\"";
print some_string; // should output echo ""hi""
To try out my solution do something like this:
// might need to fiddle with the escaping here
var some_other_string : string = "echo \\\"\\\"hi\\\"\\\"";
print some_other_string; // should output echo \"\"hi\"\"

You're passing your string through multiple string interpreters. First Specman's, then your shell's string interpreter.
You can debug getting your string through Specman's interpreter first by printing out command you want to pass to the shell first
message(None,"echo [...]")`
Once the printed command looks like it would when you execute it on the shell, then it is ready to be put into output_from command. You can build up the shell command using normal Specman string manipulation functions.

Related

Backslash in string from standard input, no way to stripe it

I have a string that comes from the standard input in Xcode, using Swift. When I type in my string, I write something like this :
He told me "Hello maaan"
What I see when I print my message after putting a breakpoint is this :
"He told me \"Hello maaan""
Now, the quotes at the start and the end can be ignored, but what's that backslash? If I run this code in the console
po message.contains("\\")
it returns me false. The thing is that I need to run a regex on that string and the regex fails because of that \ char. What's the solution?
EDIT
If I transform my string to a NSString, the console prints this :
He told me "Hello maaan
In order for the compiler to ignore the quotation marks you'll need to add the backslashes before both.
So, you'll need to format your string as so:
var string = " He told me: \"Hello Man\"."
print(string)

Xcode breakpoint shell command argument length

Trying to pass a large string to a shell script using a breakpoint in Xcode
let value = Array(repeating: "a", count: 1500).joined()
let string = "{\"key\": \"\(value)\"}"
Unfortunately, the string is being truncated. Is this limitation documented and can it be overcome?
It's been nearly a year since you asked this, and I'm not sure if it will solve your question, but I've recently had a similar problem so thought I'd share my solution.
I had two issues:
LLDB was truncating any arguments to my shell script (and string variables printed in the console using po foo) to 1023 characters. I believe this is the issue to which your question relates.
Xcode was incorrectly confusing a comma , in my string as a separator for multiple arguments (e.g. passing foo, bar, and baz as arguments to the script wouldn't work correctly if any of the variables contained a , as Xcode would try to create another argument).
So, firstly, the LLDB issue...
It seems that by default LLDB has a limit on the character length that it will print to the console (or pass to a shell script via a breakpoint argument) of around 1023 characters. You can easily change this to something larger by setting another breakpoint before the breakpoint that uses your variable and running (lldb) set set target.max-string-summary-length 10000 in the console. This can be a bit annoying so I created a ~/.lldbinit file and placed set set target.max-string-summary-length 10000 in there instead so I don't have to keep setting it in the console.
Secondly, the comma issue...
Inside the Edit breakpoint... menu that you provided a screenshot of above there is the option to not only provide a path to a script but to also provide arguments. I can see from your question that you provided the argument #string#. For my script, I was passing multiple arguments, which Xcode allows you to do using a comma separated list, e.g. #foo#, #bar#, #baz#. Each of these arguments was a string.
I noticed that sometimes one or more of these strings would truncate if they contained a comma: ,.
So the string:
{ "num_friends" : "7" }
would be passed to my script as expected. But the string:
{ "num_friends" : "7", "num_deleted_friends" : "1" }
would truncate and would be passed to my script as two separate arguments. It seems that Xcode would split any string with a , even when entered using #string#.
I validated this in my script by simply using something like:
for var in "$#"
do
echo "$var"
echo "===="
done
Where $# expands to contain each argument. From this I could see that #string# was being correctly passed to my script but separated as multiple arguments wherever there was a ,. So if #string# contained a comma my script would print:
#"{ \"num_friends\" : \"7\"
====
\"num_deleted_friends\" : \"1\" }"
instead of what I expected which was:
#"{ \"num_friends\" : \"7\", \"num_deleted_friends\" : \"1\" }"
So it seems like it might be a bug in how Xcode passes strings inside # expressions in the breakpoint editor window.
My crude solution has been to just replace any commas with another character and then replace them back again inside my script. There's probably a better way to do this but I don't require it for my needs.

Passing a variable to a command in a script

I've been searching all over the place and since I'm taking my first steps in PERL this might be one of he dumbest questions but here it goes.
So I'm creating a script to manage my windows and later bind it to keyboard shortcuts, so I I'm trying to run a command and passing some variables:
my $command = `wmctrl -r :ACTIVE: -e 0,0,0,$monitors->{1}->{'width'}/2,$monitors->{1}->{'height'}`;
But I get an error saying I'm not passing the right parameters to the command, but if I do this, everything works great:
my $test = $monitors->{1}->{'width'}/2;
my $command = `wmctrl -r :ACTIVE: -e 0,0,0,$test,$monitors->{1}->{'height'}`;
So do I really have to do this? assign it first to a variable and then pass it, or there's a more elegant way of doing it?
The backticks operator (or the qx{}) accepts A string which is (possibly) interpolated. So accepts string and not expression like $var/2.
Thats mean than the $variables ($var->{1}->{some} too) are expanded but not the arithmetic expressions.
Therefore your 2 step variant works, but not the first.
If you want evaluate an expression inside the string you can use the next:
my $ans=42;
print "The #{[ $ans/2 ]} is only the half of answer\n";
prints
The 21 is only the half of answer
but it is not very readable, so better and elegant is what you're already doing - calculate the command argument in andvace, and to the qx{} or backticks only pass the calculated $variables.

Passing command line argument to an application

I would like to execute an application from a Perl script.
The Perl script calls the application with a variable as a parameter, the value of which is a long string with lots of spaces within.
The application interprets these as separate strings but I want all of it as one string.
Here's the code in the Perl script:
$command = "Hello world here i come. Hope this works"
when the Perl script tries to call the application
./a.out $command
and within the applicaion I try to access argv[1], I only get the string Hello. argv[2] contains world but I want argv[1] to contain the complete string contained in $command. How do I do it?
Use a multiple argument form of exec
exec "./a.out", $command
In this way the shell doesn't get involved

how to add double quote to a string in Perl

my code looks following:
$id = "PROD121213123";
I am passing this to a function and adding this to it
"\"$wi_id\""
where $wi_id looks like my $wi_id = $_
After "\"$wi_id\"" the value looks like "PROD121213123" which I checked in Eclipse debugger (using EPIC)
I am calling curl.exe from Perl and it looks like this "" is omitted during execution. How can I have "" to the string and still execute using CURL?
It sounds like you're doing the equivalent of
my $id = "\"PROD121213123\""; # String <<"PROD121213123">>
system "curl.exe ... $id ..."; # curl sees <<PROD121213123>>
It's because the quotes have special meaning to the "shell". Command line parsing is a bit of a mess in Windows (nothing to do with Perl), so you might not be able to even pass double-quotes to curl. I'd try using the multiple arg version of system.
You're trying to pass a quotes string to a command which is called though a shell. To accomplice that, you'll need to escape the quotes to hide them for the shell:
my $id = q(\"PRD121212\");
system qq(curl.exe ... $id ...);
HTH,
Paul