File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed
Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,8 @@ import (
1818 "bytes"
1919 "fmt"
2020 "io"
21+ "os"
2122 "os/exec"
22- "runtime"
23- "strings"
2423 "unicode/utf8"
2524
2625 "golang.org/x/text/encoding/simplifiedchinese"
@@ -52,22 +51,26 @@ func GetTextFromMarkitdown(path string) (string, error) {
5251 return "" , fmt .Errorf ("GetTextFromMarkitdown() error, markitdown does not exist" )
5352 }
5453
55- var cmd * exec.Cmd
56- isWindows := strings .Contains (strings .ToLower (runtime .GOOS ), "windows" )
57- if isWindows {
58- cmd = exec .Command ("cmd" , "/C" , fmt .Sprintf ("markitdown < %s" , path ))
59- } else {
60- cmd = exec .Command ("sh" , "-c" , fmt .Sprintf ("markitdown < %s" , path ))
61- }
62-
63- err := cmd .Run ()
54+ // Open the input file
55+ file , err := os .Open (path )
6456 if err != nil {
65- return "" , err
57+ return "" , fmt . Errorf ( "failed to open file: %w" , err )
6658 }
59+ defer file .Close ()
60+
61+ cmd := exec .Command ("markitdown" )
62+
63+ cmd .Stdin = file
6764
6865 var out , stderr bytes.Buffer
6966 cmd .Stdout = & out
7067 cmd .Stderr = & stderr
68+
69+ err = cmd .Run ()
70+ if err != nil {
71+ return "" , fmt .Errorf ("markitdown execution failed: %v: %s" , err , stderr .String ())
72+ }
73+
7174 outputBytes := out .Bytes ()
7275 if utf8 .Valid (outputBytes ) {
7376 return string (outputBytes ), nil
You can’t perform that action at this time.
0 commit comments