CCL doesnot run shell command normally? - ccl

? (run-program "ls" '() :output *standard-output*)
money.lisp
ssqHitNum.txt
ssqNum.txt
#<EXTERNAL-PROCESS (ls)[1019] (EXITED : 0) #x3867BACE>
? (run-program "tail ssqHitNum.txt" '() :output *standard-output*)
#<EXTERNAL-PROCESS (tail ssqHitNum.txt)[1020] (EXITED : 71) #x38679E56>
Why canot CCL run "tail ssqHitNum.txt" ?

As detailed in the docs, http://ccl.clozure.com/ccl-documentation.html#Running-Other-Programs-as-Subprocesses, you need to capture the output. This is one of the documented ways:
(with-output-to-string (s)
(ccl:run-program "ls" nil :output s))
The output is now contained in s and you can do whatever you want with it.

Try running it as:
(run-program "tail" '("ssqHitNum.txt") :output *standard-output*)
The second argument to run-program must contain the parameters.

Related

What's a bad file descriptor?

I have the next system swi-prolog in a file call 'system.pl';
helloWorld :- read(X), write(X).
And i want to test it, then, i write it;
:- begin_tests(helloWorld_test).
test(myTest, true(Output == "hello")) :-
with_output_to(string(Output), getEntry).
:- end_tests(helloWorld_test).
getEntry :-
open('testcase.test', read, Myfile),
set_input(Myfile),
process_create(path(swipl), ['-g', 'main', '-t', 'halt', 'system.pl'], [stdin(stream(Myfile)), stdout(pipe(Stream))]),
copy_stream_data(Stream, current_output),
close(Myfile).
In testcase.test is contained the following;
hello.
Ok, now, when i call to swipl -g run_tests -t halt system.pl i get it;
% PL-Unit: helloWorld_test ERROR: -g helloWorld: read/1: I/O error in read on stream user_input (Bad file descriptor)
ERROR: c:/programasvscode/prolog/programasrandom/system.pl:40:
test myTest: wrong answer (compared using ==)
ERROR: Expected: "hello"
ERROR: Got: ""
done
% 1 test failed
% 0 tests passed
ERROR: -g run_tests: false
Warning: Process "c:\swipl\bin\swipl.exe": exit status: 2
I tried use read/2 with current_input but i got the same with the difference of read/2 instead read/1
What does mean it? any solve?

Emacs call-process stumbles upon supplied args content

I'm puzzled by unexpected behavior of a call-process call.
Here's a little function:
(defun work-in-progress()
"run ledger report and output result in current buffer.
The intention is to run following command (works perfectly from shell):
`ledger -U csv --sort date --file ledger-file child`
where ledger-file is a known and defined variable.
The problem is that the command fails with:
`Error: Illegal option -`
"
(interactive)
(cd ledger-dir)
(setq child "peter")
(setq parms "-U csv --sort date --file")
(setq prog "ledger") ; should be found via path variable or so
(call-process prog nil t t parms ledger-file child)
)
I've played around with the sequence of the ledger command options, but emacs always seems to complain about the first option or all options in the parms variable:
e.g.
(setq parms "--sort date -U csv --file")
results in
Error: Illegal option --sort date -U csv --file
iso
Error: Illegal option -
The ledger cli program isn't fussy about arguments sequence, both described option sequences work perfectly well when calling ledger at the command line.
This truly puzzles me. The documentation reads
call-process program &optional infile destination display &rest args
and infile is set to nil, destination as well as display are t, so why doesn'it grok the content of args variable?
Any help, correction and/or suggestion would be sincerely appreciated!
The tail of the list should be a sequence of strings, each corresponding to one argument.
(setq parms '("-U" "csv" "--sort" "date" "--file"))
(setq prog "ledger")
(apply #'call-process prog nil t t (append parms '(ledger-file child)))
You need apply to make the result of append into a continuation of the static list of arguments to call-process.
I had to guess what ledger-file and child are; if they are not strings, you need to convert them to strings.
To briefly recapitulate how the shell parses arguments, the command line
echo foo "bar $baz" 'quux $baz'
gets turned into the string array
'("echo" "foo" "bar <<value of baz>>" "quux $baz")
(to use a Lispy notation) and passed as arguments to execlp.
The solution is to pass each parameter as a separate string:
(defun work-in-progress()
"run ledger report and output result in current buffer. "
(interactive)
(cd ledger-dir)
(setq child "peter")
(setq prog "ledger") ; should be found via path variable or so
(call-process prog nil t t "--sort" "date" "-U" "csv" "--file" ledger-file child)
)

Not able to Pass Switch Parameter from Command Shell Prompt

I have a PowerShell script which has couple of parameters including a switch parameter.
The below command executed within PowerShell works as expected:
\\localhost\Test\Code\DataPullResults.ps1 -TestName 'Test survey' -QUser 'sdasch#gmail.com' -SqlServerInstanceName localhost -SqlDatabaseName MyDatabase -Load:$True -ErrorAction Continue;
But when I ran the same command from command prompt I get an error:
\\localhost\Test\Code\DataPullResults.ps1 : Cannot process
argument transformation on parameter 'FullLoad'. Cannot convert value
"System.String" to type "System.Management.Automation.SwitchParameter".
Boolean parameters accept only Boolean values and numbers, such as $True,
$False, 1 or 0.
Below is the command which I have used to execute from the command prompt:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe powershell.exe -ExecutionPolicy ByPass -File \\localhost\Test\Code\DataPullResults.ps1 -TestName 'Test survey' -QUser 'sdasch#gmail.com' -SqlServerInstanceName localhost -SqlDatabaseName MyDatabase -Load:$True -ErrorAction Continue;
Here Load is a Switch Parameter.
powershell.exe does not fully evaluate script arguments when the -File parameter is used (source). So you should use -command instead:
powershell.exe -Command \\localhost\Test\Code\DataPullResults.ps1 -TestName 'Test survey' -QUser 'sdasch#gmail.com' -SqlServerInstanceName localhost -SqlDatabaseName MyDatabase -Load:$True -ErrorAction Continue;
But beside that, note that you don't have to pass a boolean to a switch value. That means, if you omit -Load, $load will be set to $false. And if you pass -Load (without $true), it will get set to $true.
Aslo, did you noticed, that you are calling powershell.exe twice?
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe powershell.exe

Getting interactive user input at terminal: provide prompt with editable default in racket

in bash, i can write a script which not only a) allows the user to input a string, but b) also prompts the user for a default value of that string, and c) allows that value to be edited before hitting enter:
#!/bin/bash
default_title="Another `date +%A` in paradise"
read -e -r -p "Title: " -i "${default_title}" input
title="${input:-default_title}"
echo "Title will be: ${title}"
how can I accomplish the same thing in Racket?
i can't see how to do it with racket's read-line, which does let me read a line at the terminal (a), but does not let me provide a default value to the user (b) which they can then edit (c).

How to get SQLCMD to output errors and warnings only

How can you get SQLCMD, when executing a SQL script file, to just output any errors or warnings it encounters?
I essentially dont want information based messages to be output.
It's not possible to prevent SQLCMD returning non-error output messages by passing it a parameter.
However, what you can do is redirect error messages to STDERR, then direct all other messages to NUL.
This is done by passing the -r parameter. From books online:
-r[ 0 | 1] msgs to stderr
Redirects the error message output to the screen (stderr). If you do not specify a parameter or if you specify 0, only error messages that have a severity level of 11 or higher are redirected. If you specify 1, all error message output including PRINT is redirected. Has no effect if you use -o. By default, messages are sent to stdout.
Set -r depending on exactly which error messages you want to display, but to display all error message output, an example command would be:
sqlcmd -Q "select 1 as a; select 1/0 as b" -E -r1 1> NUL
Just as an addition to this, if you are sending errors out to file, I found this https://www.simple-talk.com/sql/sql-tools/the-sqlcmd-workbench/
which I have used. If you omit setting the OUT, then you only get an error log created.
So you have a command like this :
sqlcmd -x -E -S MyServer -i C:\MySQLBatchToRun.sql
Then in MySQLBatchToRun.sql , something like this
USE MyDatabase
:Error C:\MyErrorLog.txt
:r C:\MySQLScript.sql
GO
In MySQLScript.sql you have the actual SQL to run. It's a bit convoluted, but works. The only issue I have is that it seems to create an empty error log file, even if there is not an error.
It looks like print statements are sent to stderr with -r1 so you can use them to log separate from your output like so:
sqlcmd -Q "print 'hello logfile';select 'Ted' as bro" -r1 1> C:\output.txt 2> C:\logfile.txt
This also works with -i inputfile like:
sqlcmd -i helloTed.sql -r1 1> C:\output.txt 2> C:\logfile.txt
helloTed.sql:
print 'hello logfile';
select 'Ted' as bro
Probably you could use -Q and insert exec a stored proc that contains prints.