Perl System() function [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to know what would be the equivalent C# code for the perl system() function, see below code
$flac = `/usr/bin/which flac`;
($fh, $tmpname) = tempfile("stt_XXXXXX", DIR => "/tmp", UNLINK => 1);
/// Some code for recording
$endian = (unpack("h*", pack("s", 1)) =~ /01/) ? "big" : "little";
$samplerate = 8000;
$format = sln;
if(system($flac, $comp_level, "--totally-silent", "--channels=1", "--endian=$endian", "--sign=signed", "--bps=16", "--force-raw-format", "--sample-rate=$samplerate", "$tmpname.$format") != 0)
{
if (open($fh, "<", "$tmpname.flac"))
{
$audio = do { local $/; <$fh> };
close($fh);
}
}
Please help me solve my problem, digging on internet won't help me. Thanks

The system call in perl most likely calls the command line processor of the operating system with the given string.
In C#, you would use System.Diagnostics.Process.Start to start a new process. The MSDN has examples to start from.

Related

Mid as target of an assignment [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I try just an old VB application in c# to convert, while I've encountered this line of code:
Mid(strData, intPosition + 1, intLenght) = strValue
How can it be translated into c#?
You would have to combine Remove and Insert, something like:
strData.Remove(intPosition, intLenght).Insert(intPosition, strValue);
The above assumes that the length of strValue was equal to intLenght. If strValue might be longer, then to replicate the Mid statement, we would need to do:
strData.Remove(intPosition, intLenght)
.Insert(intPosition, strValue.Substring(0, intLenght));

Copying file from one directory to another with c# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a directory path like this \servername\DirectoryName\.csv and in that there are multiple csv files of similar name pattern now I want to copy that from one directory to another in c#.Can anyone help me out with this.
var sourceDir = #"c:\sourcedir";
var destDir = #"c:\targetdir";
var pattern = "*.csv";
foreach (var file in new DirectoryInfo(sourceDir).GetFiles(pattern))
{
file.CopyTo(Path.Combine(destDir, file.Name));
}
Use Files.Copy() method. See msdn here.

Can't use 'contains' in LINQ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
string last = url.Substring(url.LastIndexOf('/') + 1);
var provisionedSiteRequestRep = provisioningRequestRepository.SelectFirst(new WhereSpecification<ProvisioningRequest>(result => result.SiteUrl.Contains(last.ToString())));
Some time i am getting the null values of last.tosting() so i am getting exception for this code how to resolve this?
You are facing problem on this line
(result => result.SiteUrl.Contains(last.ToString());
Can you please check that SiteUrl is type of string otherwise it not going to work for you.
because last is type of string and Contains is method supported by string type ...
or
otherwise last need to be enumebrable collection and siteurl also enumerable collection than and only than Contains is supported

Eval() javascript code from within C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to eval() and run this javascript code from my C# program, but it won't even debug.
How can I do this?
string jsFunc = "eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('8 4=\'6/13!)!6/12))6/19))))2!,!18*!16!15*!,!:14*-!17:9*!,!26***<\';8 5=\"\";20(3=0;3<4.24;3++){10(4.7(3)==25){5+=\'\\&\'}11 10(4.7(3)==23){5+=\'\\!\'}11{5+=21.22(4.7(3)-1)}};5;',10,27,'|||i|s|m|Nbui|charCodeAt|var||if|else|bct|spvoe|521|8477|_|73|2689|njo|for|String|fromCharCode||l{�ength|28|4451'.split('|')))";
JSEval.JSEval eval = new JSEval.JSEval();
string expression, result;
Console.Write("Выражение: ");
expression = jsFunc;
try
{
result = eval.Eval(expression).ToString();
}
catch
{
result = "!!!";
}
One potential problem, if I am permitted to hazard a guess based on the slim details available, is the odd character sequence found in the string:
...||l{�ength|28|4451'.split('|')))";
Perhaps you should remove the {� and re-run the code.
To elaborate on other meanings of the phrase "code don't debug":
Ensure the project is configured to build in Debug mode.
If your expectation is that you can step through the JavaScript, this will not be possible. You should instead debug the JavaScript using something like Firebug.
If you cannot mentally debug the JavaScript, because it has been minified, you should look at a tool to unpack the JavaScript into something more human readable.

Fibonacci Recursion [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Alright, so I've tried to search for it, and yes, I found the answer, but not the explanation of it, I'd like to know the explanation of the following result:
float fib(int num)
{
float result;
if (num==1)
result=0;
else
{
if (num==2)
result=1;
else
result=fib(num-1)+fib(num-2);
}
return result;
}
Start here: http://en.wikipedia.org/wiki/Recursion
Then go here: http://en.wikipedia.org/wiki/Fibbonaci_Series
The method called fib() calls itself in certain cases, and does not call itself in other cases (known as base cases).

Categories

Resources