I have some problems calling commands from a Linux .net core consol application.
Sub Main()
Dim PI As New ProcessStartInfo
Using Proc As New Process
With PI
.FileName = "cat"
.Arguments = "/etc/*-release"
.RedirectStandardOutput = True
.UseShellExecute = False
.CreateNoWindow = True
End With
Proc.StartInfo = PI
Proc.Start()
PI = Nothing
Console.Write(Proc.StandardOutput.ReadToEnd)
End Using
End Sub
I get this error:
cat: '/etc/*-release': No such file or directory
It work if I disable redirection and set UseShellExecute = True, but I would like to be able to use the output in my code.
When you run a command like
cat /etc/*-release
The linux shell (bash, probably) evaluates each argument, then calls the program with the evaluated arguments. Simple words evaluate to themselves, but variables (like $SOME_ARGUMENT) and patterns (like *) evaluate to the values and file names. So the shell really evaluates the above into (assuming there is just one file):
cat /etc/os-release
And so the cat program just gets that one argument - without any globs like *.
If you want to emulate that behaviour in your program, you need to set UseShellExecute to True.
Or, perhaps you can do the evaluation yourself. APIs like Directory.EnumerateFiles let you do that:
Dim textFiles = Directory.EnumerateFiles("/etc/", "*-release")
Then you need to walk this collection and use the exact file name as your .Arguments value.
Edit: But to go a bit further, why are you even trying to do this? If you have read the file completely, why call cat. Why not just Console.WriteLine() the file itself rather than calling cat?
Ahhh....got it!
I just have to use bash -c ""cat ""/etc/*-release""""
Sub Main()
Dim PI As New ProcessStartInfo
Using Proc As New Process
With PI
.FileName = "bash"
.Arguments = "-c ""cat ""/etc/*-release"""""
.RedirectStandardOutput = True
.UseShellExecute = False
.CreateNoWindow = True
End With
Proc.StartInfo = PI
Proc.Start()
PI = Nothing
Console.Write(Proc.StandardOutput.ReadToEnd)
End Using
End Sub
Related
I wrote a script in Matlab on windows system. Now I changed to linux system and I tried to use my script on linux in matlab also. But it does not work.
I got a problem with the data import part of my script:
data = {};
for i = 1:numel(filelist)
filename = filelist{i};
filename = [selpath '\' filename];
delimiter = ',';
startRow = 2;
formatSpec = '%*q%*q%*q%q%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
fclose(fileID);
tmp_data = str2double(dataArray{1});
data{i} = tmp_data;
end
If I run my script I got the following error from matlab:
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in justus_tem (line 21)
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,startRow-1, 'ReturnOnError',
false, 'EndOfLine', '\r\n');
When I run the same script on windows I do not get the Error. In linux system the fileID is always -1
Has somebody a tip or knows what I do wrong? I tried different permissions for fopen but it does not work either.
Linux uses a forward slash (/) as the file separator, you have hard-coded the Windows compatible backward slash (\). Instead, consider either
Using filesep for a system-dependent file separator
filename = [selpath, filesep, filename];
Or use fullfile to build the path for you
filename = fullfile(selpath, filename);
I would like to run two Python 3 scripts from SPSS syntax window. It is possible to perform it using BEGIN PROGRAM-END PROGRAM. block or SCRIPT command. This time I need to find a solution using second command.
Simplified code:
*** MACROS.
define export_tabs (!positional !tokens (1))
output modify
/select logs headings texts warnings pagetitles outlineheaders notes
/deleteobject delete = yes.
OUTPUT EXPORT
/CONTENTS EXPORT = visible LAYERS = printsetting MODELVIEWS = printsetting
/XLSX DOCUMENTFILE = "doc.xlsx"
OPERATION = createsheet
sheet = !quote(!unquote(!1))
LOCATION = lastcolumn NOTESCAPTIONS = no
!enddefine.
define matrix_tab (!positional !charend('/')
/!positional !charend('/')
/!positional !charend('/')
/!positional !charend('/')
/stat = !tokens (1))
!do !i !in (!3)
ctables
/mrsets countduplicates = no
/vlabels variables = !concat(!1,_,!2,_,!i) display = label
/table !concat(!1,_,!2,_,!i)
[rowpct.responses.count !concat(!unquote(!stat),"40.0"), totals[count f40.0]]
/slabels position = column visible = no
/clabels rowlabels = opposite
/categories variables = !concat(!1,_,!2,_,!i) order = a key = value
empty = include total = yes label = "VALID COUNT" position = after
/titles title = !upcase(!4).
!doend
!enddefine.
*** REPORT.
* Sheet 1.
output close all.
matrix_tab $Q1 / 1 / 1 2 / "QUESTION 1" / stat="pct".
script "C:\path\script 1.py".
script "C:\path\script 2.py".
export_tabs "Q1".
* Sheet 2.
output close all.
matrix_tab $Q2 / 2 / 3 4 / "QUESTION 2" / stat="pct".
script "C:\path\script 1.py".
script "C:\path\script 2.py".
export_tabs "Q2".
When I run a block for the first sheet everything works fine. However, when I run a block for the second sheet SPSS doesn't execute Python scripts and jumps straight to export_tabs macro (problems with synchronization?). I thought a problem had been possibly in a way I executed SCRIPT command. So I tried this:
script "C:\path\script 1.py" pythonversion = 3.
script "C:\path\script 2.py" pythonversion = 3.
but in effect SPSS - even though the syntax window coloured these parts of syntax - returned this error message:
>Error # 3251 in column 152. Text: pythonversion
>The SCRIPT command contains unrecognized text following the the file
>specification. The optional parameter must be a quoted string enclosed in
>parentheses.
>Execution of this command stops.
Has anyone of you had such problem and/or have an idea why this happens?
NOTE: Both Python scripts run smoothly from the Python 3.4.3 shell installed with the version of SPSS I have, thus I don't think the core of the problem is within those codes.
This seems to be a document defect in the way this keyword was implemented. I have been able to replicate it and have logged a defect with IBM SPSS Statistics Development.
In this case, the order matters. Rather than this:
script "C:\path\script 2.py" pythonversion = 3.
Try instead:
script pythonversion = 3 "C:\path\script 2.py".
Connecting to switch using expect spawn
child = pexpect.spawn('telnet ' + self.device_ip, timeout = 30)
When trying to run the below line, Im getting nothing as output
child.sendline('python script.py')
Can someone help me to run the python file over here?
I used
print("%s"%(child.before))
to print the output but it prints nothing
Make sure when you are using child.before that you have a child.expect statement beforehand. To put simply expect defines the text buffer that before references. Ex.
child = pexpect.spawn('telnet ' + self.device_ip, timeout = 30)
child.sendline('python script.py')
child.expect('user#abcd1234>')
remotehostoutput = (child.before)
Running a cucumber script in Jruby 9.1.7.0. The output goes to STDOUT. How can I get it to save it into a local variable ?
require 'cucumber'
require 'stringio'
#output = StringIO.new
features = 'features/first.feature'
args = features.split.concat %w(-f html)
# Run cucumber
begin
# output goes to STDOUT
Cucumber::Cli::Main.new(args).execute!
rescue SystemExit
puts "Cucumber calls #kernel.exit(), killing your script unless you rescue"
end
If you type in cmd "cucumber --help"
-o, --out [FILE|DIR] Write output to a file/directory instead of STDOUT. This option
applies to the previously specified --format, or the
default format if no format is specified. Check the specific
formatter's docs to see whether to pass a file or a dir.
You can modify your code with
args = features.split.concat %w(-f html -o test.html)
You can also write it in a tempfile and read the value from the file.
require 'cucumber'
require 'tempfile'
require 'securerandom'
filename = "#{SecureRandom.urlsafe_base64}"
file = Tempfile.new(filename)
filepath = "#{file.path}"
features = "cucumber/ars/features/ars_additional.feature"
args = features.split.concat %w(-f html -o)
args << filepath
Cucumber::Cli::Main.new(args).execute!
#output = file.read
file.close
file.unlink
need_resched:
preempt_disable();
cpu = smp_processor_id();
rq = cpu_rq(cpu);
rcu_note_context_switch(cpu);
prev = rq->curr;
switch_count = &prev->nivcsw;
release_kernel_lock(prev);
I would like to ask is: "need_resched:" What is the role.
In detail,The linux kernel version is 2.6.35.3.
need_schedule: is simply a label. Later in the code you will find:
if (need_resched())
goto need_resched;
I.e., if the rescheduling flag ist set (what is tested by need_reschedule()), this point in code is executed (again).