If you just use system() you create a shell process that will do
"whatever", probably in a windows shell, but you don't get to see the
output of the shell without further tricks.
Your program may be running under an MSYS2 shell or from a CMD shell; since
you want results from MSYS2 shell you should just invoke bash at the
outset, maybe:
cmdstring= "c:\msys64\usr\bin\bash.exe -lc 'cd $OLDPWD && tar tzf
foobar.tar.gz | head -1 | cut -f1 -d'"/'" > dirname "
then execute ...
<int result = system( cmdstring)>
 then read...
< file dirname -> dirname>

If you wish to read stdout from the process you create you will need to go
through CreateProcessW(), open a pipe to recieve stdout and,
if stdout will be larger than about 4000 bytes, buffer out the reception.

I haven't tested any of this so ygwypf.

Greg

On Thu, Jan 10, 2019 at 2:16 PM Vincent Torri <vincent.to...@gmail.com>
wrote:

> Hello
>
> I would like to know, programmatically, if the the directory created
> when a tarball is decompressed exists or not. The tarball is in this
> directory:
>
> D:/Documents/msys2/opt/ewpi_test/share/ewpi/packages/foobar
>
> So I want to execute with system() :
>
> cd D:/Documents/msys2/opt/ewpi_test/share/ewpi/packages/foobar &&
> dir_name=`tar tzf foobar.tar.gz | head -1 | cut -f1 -d"/"` && cd
> $dir_name
>
> If dir_name does not exists, cd will throw an error. I can use also a
> test. The problem is not there anyway : when executed with system(),
> dir_name is not known.
>
> As there are problems, i first tried this test : using cygpath and
> storing the result in a variable, then display this variable.
>  :
> 1) Directly in MSYS2 :
>
> cygpath -u D:/Documents/msys2/opt/ewpi_test
>
> returns of course :
>
> /opt/ewpi_test
>
> 2) With this code :
>
>   char *cmd = "prefix=`cygpath -u D:/Documents/msys2/opt/ewpi_test` &&
> echo $prefix";
>   printf("%d\n", system(cmd));
>
> I have this message (in french) :
>
> 'prefix' n'est pas reconnu en tant que commande interne
> ou externe, un programme exécutable ou un fichier de commandes.
>
> Which can be translated as
>
> 'prefix' is not an internal command, or an external command, or a
> executable program, or a command file
>
> 3) With this code (I execute the command with bash) :
>
>   char *cmd = "/bin/bash prefix=`cygpath -u
> D:/Documents/msys2/opt/ewpi_test` && echo $prefix";
>   printf("%d\n", system(cmd));
>
> I have this message (in french) :
>
> Le chemin d'accès spécifié est introuvable.
>
> which can be translated as
>
> The specified access path can not be found
>
> Does someone know how I can make the tests 2) a,d 3) as expected
> (display the value /opt/ewpi_test like in 1) ?
>
> thank you
>
> Vincent Torri
>
>
> _______________________________________________
> Msys2-users mailing list
> Msys2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/msys2-users
>
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to