Here another `hexdump()`:
import strutils
proc hexDump*(s: string | cstring, cols: int = 16, offs: int = 2): string =
result = newStringOfCap(s.len * 3 - 1 + (s.len div cols + 1) * (offs + 2))
var newLine = true
for idx, c in s:
if idx > 0:
> @Flyx For such a case something like a hexdump echo of strings would be nice.
> I was looking for such proc some months ago -- is there something available?
You can use `repr` to get a better idea of what characters are contained a
string.
@luntik2012: From documentation of `execProcess`:
> WARNING: this function uses poEvalCommand by default for backward
> compatibility.
This means that it executes the command within a shell, which is probably
responsible for the trailing newline.
@Stefan_Salewski: Well, it's easy enough to
@flyx Thank you, it works. And it's interesting, because after executing
"that_cmd >> file" file doesn't contain trailing whitespaces O_o
@luntik2012 Sorry, saw my mistake short time period after sending the post...
@Flyx For such a case something like a hexdump echo of strings would be nice. I
was looking for such proc some months ago -- is there something available?
Why not use echo to see the content of the string you pass to parseInt?
Note: for bash command expr / indicates integer division. For Nim / is floating
point division, you may use div for integer division, or you may round the
floating point result. So may guess is that you pass a floating
execProcess return type is TaintedString, so I don't think it's float(bash
performs division and returns string)
The problem is that the result of `execProcess` contains trailing whitespace (a
newline in this case). Try:
return execProcess(command & "" & filepath & ) /
1000""").strip.parseInt
proc getLen*(filepath: string): int =
const command = """expr $(mediainfo --Inform="Audio;%Duration%" """
return execProcess(command & """ & filepath & ) /
1000""").parseInt
I'm executing this command in bash and getting result "347":
expr $(mediainfo